wood burning stoves 2.0*
The moose likes Servlets and the fly likes Async Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Async Servlet" Watch "Async Servlet" New topic
Author

Async Servlet

Eugene Rabii
Ranch Hand

Joined: Apr 24, 2009
Posts: 30
Hello dear ranchers hear is my question,

Trying to understand the Async Servlet for a few days now, no luck yet. May be you could help me. So, what literally happens when we call startAsync()? The request and the response gets somehow put on the server, while the "async" job gets done? For example:

AsyncContext context = request.startAsync();
context.start(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
context.complete();
response.getWriter().print("Done");

So, what this means is that the initial http Thread "releases" the request, some other worker thread picks it up and does the waiting (the async task) and the the http Thread builds the response.

I mean, from what I have read so far, the async support is for releasing some Thread, right? But if we release some Thread, the async job is done by some other Thread anyway. So, where do we win in the first place? Or may be some Threads are not that expensive as others?

P.S. There are no stupid questions, there are silly answers.

Thanks a lot!
Eugene.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Async Servlet