What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
Hi, I don't understand the meaning of timeout of an asynchronous operation. Servlet 3.0 says The time out applies to the AsyncContext once the container-initiated dispatch during which one of the ServletRequest.startAsync methods was called has returned to the container. But when is the

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread Mark Thomas
On 24/05/2013 09:05, jie tang wrote: Hi, I don't understand the meaning of timeout of an asynchronous operation. Servlet 3.0 says The time out applies to the AsyncContext once the container-initiated dispatch during which one of the ServletRequest.startAsync methods was called has returned

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
Thanks. So the only way to avoid the invocation of AsyncListener.onTimeout is that we invoke AsyncContext.complete or AsyncContext.dispatch? 2013/5/24 Mark Thomas ma...@apache.org On 24/05/2013 09:05, jie tang wrote: Hi, I don't understand the meaning of timeout of an asynchronous

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread Mark Thomas
On 24/05/2013 09:16, jie tang wrote: Thanks. So the only way to avoid the invocation of AsyncListener.onTimeout is that we invoke AsyncContext.complete or AsyncContext.dispatch? Or write some content to the response. Mark 2013/5/24 Mark Thomas ma...@apache.org On 24/05/2013 09:05,

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
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? 2013/5/24 Mark Thomas ma...@apache.org On 24/05/2013 09:16, jie tang wrote: Thanks. So the only way to avoid the invocation of

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread Mark Thomas
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

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
Thank you very much 2013/5/24 Mark Thomas ma...@apache.org 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

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
I tried the following code: final AsyncContext async = req.startAsync(); async.setTimeout(3); async.addListener(new AsyncListener(){ @Override public void onComplete(AsyncEvent event) throws IOException {

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread Mark Thomas
On 24/05/2013 10:15, jie tang wrote: I tried the following code: final AsyncContext async = req.startAsync(); async.setTimeout(3); async.addListener(new AsyncListener(){ @Override public void onComplete(AsyncEvent event) throws

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
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(3);

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread Mark Thomas
On 24/05/2013 10:27, jie tang wrote: But it means that even if I write some content to response, the onTimeout method is still called Correct. The timeout starts when the AsyncContext is started and is reset every time data is written to the response. Exactly the same way socket timeouts work.

Re: What's the meaning of timeout of an asynchronous operation

2013-05-24 Thread jie tang
I changed a little in my code: final AtomicLong writeResponseTime= new AtomicLong(0); final long timeout = 3; final AsyncContext async = req.startAsync(); async.setTimeout(timeout); async.addListener(new AsyncListener(){ @Override