wood burning stoves 2.0*
The moose likes Servlets and the fly likes Asynchronous servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Asynchronous servlets" Watch "Asynchronous servlets" New topic
Author

Asynchronous servlets

Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
In JEE6 there is support for asynchronous servlets. This means that the servlet can be called asynchronously.

I am struggling to understand how the asynchronous servlet will work in practical scenario.
e.g
1. User A makes a servlet call using a url say http:/www.example.com/app/asyn
2. The servlet returns immediately while spawning a new thread to process the servlet request
3. User A then moves to another screen
4. In the meanwhile the servlet processing finishes, then how would this response be sent to client.

If somebody can explain this it will be very helpful
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
No, that's not how it works. If the user indeed moves away from the page then the response has nowhere to go. No, the asynchronicity is merely in the servlet code. This may help: http://blogs.oracle.com/enterprisetechtips/entry/asynchronous_support_in_servlet_3
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
Thanks for the reply. It was useful.
So
essentially asynchronous servlet is useful as it helps in reusing the servlet thread when a request is being processed in a long running process.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

As far as I can see it's just a bookkeeping exercise. Instead of doing your long-running processing in the servlet's thread, you do it in some other thread instead. Nothing else changes; the client still has to wait until your long-running processing finishes before it gets the response, for example. Frankly it's difficult for me to see what problem this feature was intended to solve or why I should use it.
Stoian Azarov
Ranch Hand

Joined: Jun 01, 2011
Posts: 113
Some of the uses are:
- asynchronous EJB method invocation
- chat
- RESTful web services
- quality of service

Advantages:
- improves scalability
- not blocking container threads
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Asynchronous servlets
 
Similar Threads
Resolving Rollback, Deadlock exception
can we make response from a child thread of a servlet?
servlets: can we override service method ?if yes how and why?if no then why?
Web application and cancel a operation that take long time. How do it with EJB 3.1
What's next after servlets?