Hello Toby,
You can call request.startAsync() in Servlet B.
But you cannot call it more than once in the dispatch flow to Servlet B.
It may be hard to make such a programming mistake in Servlet B.
If there're filters along it, however, calling startAsync() again in the
same dispatch can happen.
Plus, I know that AsyncListener#onStartAsync() is called when
request.startAsync() is called.
It is clearly specified in the official Java EE API reference.
http://docs.oracle.com/javaee/6/api/javax/servlet/AsyncListener.html#onStartAsync(javax.servlet.AsyncEvent)
Notifies this AsyncListener that a new asynchronous cycle is being
initiated via a call to one of the ServletRequest#startAsync methods.
So, it is called when request.startAsync() is called in your Servlet B, for
example.
Best regards,
Eugene Chung (Korean : 정의근)
On Tue, Dec 10, 2013 at 9:50 PM, tm jee <tmjee1_at_gmail.com> wrote:
> Hi guys,
>
>
> On SWChan's blog (
> https://weblogs.java.net/blog/swchan2/archive/2011/09/08/startasync-servlet-30) it
> says
>
> AsyncListener#onStartAsync(AsyncEvent) will be invoked when the
> AsyncContext is reinitialized, for instance, when AsyncContext#dispatch() is
> invoked.
>
> In the spec (3.1) it is mentioned that
>
> java.lang.IllegalStateException should be thrown
> if AsyncContext#startAsync() method is called again within the scope of the
> same dispatch
>
>
> When i have say servlet A and servlet B.
>
> In Servlet A I do
>
> AsyncContext ac = req.startAsync();
> ac.addListener(myAsyncListener1);
> ac.start(new Runnable() {
> public void run() {
> ac.dispatch("/b"); // /b is mapped to Servlet B
> }
> });
>
>
> In Servlet B can I start another AsyncContext ?
>
> I guess i am wondering what is the scope of "the same dispatch" in this
> context? Would be glad if someone could point out what i've missed in the
> spec.
>
> Thanks
> Toby
>
>
>
>
>
>
>