But it means that even if I write some content to response, the onTimeout
method is still called


2013/5/24 Mark Thomas <ma...@apache.org>

> On 24/05/2013 10:15, jie tang wrote:
> > I tried the following code:
> >         final AsyncContext async = req.startAsync();
> >         async.setTimeout(30000);
> >
> >         async.addListener(new AsyncListener(){
> >
> >             @Override
> >             public void onComplete(AsyncEvent event) throws IOException {
> >                 System.out.println(Thread.currentThread()+"onComplete");
> >
> >             }
> >
> >             @Override
> >             public void onTimeout(AsyncEvent event) throws IOException {
> >                 System.out.println(Thread.currentThread()+"onTimeout");
> >
> >             }
> >
> >             @Override
> >             public void onError(AsyncEvent event) throws IOException {
> >                 System.out.println(Thread.currentThread()+"onError
> > "+event.getThrowable());
> >
> >             }
> >
> >             @Override
> >             public void onStartAsync(AsyncEvent event) throws
> IOException {
> >
> System.out.println(Thread.currentThread()+"onStartAsync");
> >
> >             }
> >
> >         });
> >
> >         async.start(new Runnable(){
> >
> >             @Override
> >             public void run() {
> >                 try {
> >                     async.getResponse().getWriter().write("22222");
> >                     async.getResponse().getWriter().flush();
> >                     System.out.println(Thread.currentThread()+"run");
> >                 } catch (IOException e) {
> >                     // TODO Auto-generated catch block
> >                     e.printStackTrace();
> >                 }
> >             }
> >
> >         });
> >
> > The output:
> >     Thread[http-bio-80-exec-4,5,main]run
> >     Thread[http-bio-80-exec-5,5,main]onTimeout
> >     Thread[http-bio-80-exec-5,5,main]onError null
> >     Thread[http-bio-80-exec-5,5,main]onComplete
> > Although the Runnable writes some content. The onTimeout method is still
> > invoked.
>
> As expected. 30s after you write the content, the timeout is triggered.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to