Since a servlet is blocking, a normal HTTP communication makes the thread wait. So there is a possibility that all the threads in the pool can be used up. By using the asynchronous http client framework Asynchronous HTTP Client framework (AHC javadocs), the thread can be released back into the pool and be made available for other purposes until the answer comes back. When the answer comes back, a callback is fired which then relays the response back to the client.
...
The AsyncServlet in this app uses the Asynchronous HTTP Client( AHC ) and implements the CometProcessor interface. The CometProcessor will make it's event method invoked rather than the usual service method, according to the event which occurred. The event object gives access to the usual request and response objects, which may be used in the usual way. More information about this can be read here.
...
Threads | AHC Servlet | Blocking Servlet |
---|---|---|
16 | ||
200 | ||
500 |
Code location and References
Browse the sample code at http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/
Check out code from svn using
svn co https://svn.apache.org/repos/asf/geronimo/samples/trunk/samples/async-http async-http
Browse the AHC code at http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient
Check out code from svn using
svn co https://svn.apache.org/repos/asf/geronimo/sandbox/AsyncHttpClient ahc
View AHC's javadocs at AHC javadocs