File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes help in asynchronous context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "help in asynchronous context" Watch "help in asynchronous context" New topic
Author

help in asynchronous context

Alexander Sales
Ranch Hand

Joined: Feb 21, 2011
Posts: 89

hi,


is asynchronous context in servlet 3.0 different from ajax? Or it is the same?

ajax has callbacks to change a specific position in the browser.

how to create callbacks for asynchronous context?


Thanks!


OCPJP 6, OCEWCD Java EE 6
Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Alexander Sales wrote: is asynchronous context in servlet 3.0 different from ajax? Or it is the same?

AsyncContext is entirely different from ajax. First read this article to understand what it is for and how it works. See more examples of how it works here and here.


Piyush
Alexander Sales
Ranch Hand

Joined: Feb 21, 2011
Posts: 89

So the concept of Asynchronous context is to create a back-end server processing and the client won't have to wait for the loading?...

Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Client will have to wait for the asynchronous process to complete. When the async process will be complete then only the response will be committed.
Actually this concept of asynchronous processing is not with respect to client. For the client it will take the same time to complete the request.

Think it in terms of server performance. Server has a limited number of threads in thread pool which can serve a client's request. If a request is taking a long time to complete then for that duration the thread will be blocked. This reduces the efficiency of server. Imagine a scenario where all the threads in the thread-pool are blocked. Now if a new request comes then it will have to wait for the existing threads to complete processing. This is not acceptable.

But in asynchronous processing of the request the thread which is serving the client request can return to the container without committing the response. So this thread doesn't have to wait for the lengthy operation to complete. It will put the request in async mode and then start the lengthy operation in a background thread, and return to container, without waiting for that operation to complete. This thread will now become available to serve other client requests.

Remember in async mode returning to the container does not commit the response. In fact its in the hands of background thread to commit the response by calling asyncContext.complete() or any of the dispatch() methods.

So async processing does not reduce the request processing time, but it increases the average number of threads available to handle any request.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help in asynchronous context