Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
max response time(secs)

Blocking Servlet
max response time (secs)

16

2.081

5.252

200

7.575

25.935

500

12.917

39.590

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