java asynccontext_java-ee – JavaEE 6超时后的AsyncContext行为

Java Servlet 3.0维护版本(第34页)内容如下:

A call to this method – ServletRequest.startAsync(ServletRequest req,

ServletResponse res) – ensures that the response isn’t committed when

the application exits out of the service method. It is committed when

AsyncContext.complete is called on the returned AsyncContext or the

AsyncContext times out and there are no listeners associated to handle

the time out. The timer for async time outs will not start until the

request and it’s associated response have returned from the container.

The AsyncContext could be used to write to the response from the async

thread. It can also be used to just notify that the response is not

closed and committed.

In the event that an asynchronous operation has timed out, the

container must run through these steps:

Invoke, at their onTimeout method, all AsyncListener instances registered with the ServletRequest on which the asynchronous operation

was initiated.

If none of the listeners called complete() or any of the dispatch() methods, perform an error dispatch with a status code equal

to HttpServletResponse.SC_INTERNAL_SERVER_ERROR.

If no matching error page was found, or the error page did not call complete() or any of the dispatch() methods, call complete().”

上面的最后一行是最重要的 – 将调用AsyncContext.complete(). The javadoc says:

Completes the asynchronous operation that was started on the request

that was used to initialze this AsyncContext, closing the response

that was used to initialize this AsyncContext.

关闭AsyncContext后,对其大多数方法的调用将抛出IllegalStateException.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值