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.
2013/5/24 jie tang <[email protected]>
> Thank you very much
>
>
> 2013/5/24 Mark Thomas <[email protected]>
>
>> On 24/05/2013 09:23, jie tang wrote:
>> > So if I use AsyncContext.start to run a Runnable. When that Runnable
>> does
>> > some work but not write to response, will AsyncListener.onTimeout be
>> > invoked?
>>
>> Yes, unless you set the timeout to zero or less (no timeout).
>>
>> The default value is 30 seconds.
>>
>> Mark
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>