• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Async Servlet

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic