Here's a sample code from Jersey docs for Asynchronous Services:
@Path("/resource")
public class AsyncResource {
@GET
public void asyncGet(@Suspended final AsyncResponse asyncResponse) {
new Thread(new Runnable() {
@Override
public void run() {
String result = veryExpensiveOperation();
asyncResponse.resume(result);
}
private String veryExpensiveOperation() {
// ... very expensive operation
}
}).start();
}
}
Considering that container is already in charge of releasing the connection handling thread back to the pool and handing the request processing to a worker thread, I'm wondering why we still need to spawn a new thread programmatically? Shouldn't this be just a matter of container configuration (setting number of worker threads)?