aspose file tools*
The moose likes Servlets and the fly likes Issue with Asynchronous Servlet: onStartAsync(AsyncEvent event) never called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Issue with Asynchronous Servlet: onStartAsync(AsyncEvent event) never called" Watch "Issue with Asynchronous Servlet: onStartAsync(AsyncEvent event) never called" New topic
Author

Issue with Asynchronous Servlet: onStartAsync(AsyncEvent event) never called

Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
Consider the following code fragment which may appear in an Asynchronous Servlet:

According to the specification onStartAsync(AsyncEvent event) method should be called when startAsync() is called on the request object.
According to my understanding onStartAsync(AsyncEvent event) will never be called because the AsyncListener() is added to the AsyncContext AFTER calling startAsync(). (& there is no way to add the the AsyncListener() before calling startAsync())

Am I missing anything?


Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
Any small help from anyone will be greatly appreciated.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

I think you may be a bit ahead of the curve. Not many people are using a Servlet 3.0 container yet...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ryan Slack
Greenhorn

Joined: Jun 04, 2010
Posts: 1
startAsync() can be called multiple times, and always returns the same instance of AsyncContext.

startAsync():
...
This method clears the list of AsyncListener instances (if any) that were registered with the AsyncContext returned by the previous call to one of the startAsync methods, after calling each AsyncListener at its onStartAsync method.

Subsequent invocations of this method, or its overloaded variant, will return the same AsyncContext instance, reinitialized as appropriate.

Returns:
the (re)initialized AsyncContext


If you want your listener to stay registered, even if some other code calls startAsync(), it needs to be re-registered in it's onStartAsync(AsyncEvent) method.
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
Great explanation! Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with Asynchronous Servlet: onStartAsync(AsyncEvent event) never called
 
Similar Threads
unable to retrieve cookies & logout properly
Async Listener and Request/Response objects
AsyncContext timeout
How to send request data
servlet 3.0 startAsync + http pipeline