1.A simple spring framework web app;
2.Use async controller to handle request;
3.Create a runnable job, use request.getInputStream to read data in its run method, then submit this job to user-defined thread pool;
4.Deploy the app and send post request to corresponding resource;
5.Use jboss-cli.sh to connect to server and monitor the value active-request of subsystem=request-controller. Then you may find the value is accumulated but do not decrease. The problem may not occur right away but after a while.
My code is like this:
@PostMapping("/doAsyncNormal")
public DeferredResult<ResponseEntity<String>> doAsyncNormal(HttpServletRequest request) {
System.out.println("doAsyncNormal");
final DeferredResult<ResponseEntity<String>> result = new DeferredResult<>();
asyncExecutor.execute(() -> {
try
{
String body = IOUtils.toString(request.getInputStream(), "utf-8");
System.out.println("request body: " + body);
Thread.sleep(20);
result.setResult(new ResponseEntity<>("ok", HttpStatus.OK));
}
catch (Throwable e)
{
e.printStackTrace();
result.setResult(new ResponseEntity<>("error", HttpStatus.INTERNAL_SERVER_ERROR));
}
});
return result;
}