users@servlet-spec.java.net

[servlet-spec users] Re: AsyncListener#onStartAsync

From: Shing Wai Chan <shing.wai.chan_at_oracle.com>
Date: Tue, 10 Dec 2013 09:11:21 -0800

Yes, you can start async in Servlet B.
The paragraph below prevents the async started twice within a
servlet/filter, etc.

Shing Wai Chan

On 12/10/13, 4:50 AM, tm jee 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
>
>
>
>
>
>