jakarta-ee - 超时后的JavaEE 6 AsyncContext行为

标签 jakarta-ee asynchronous

AsyncContext超时后的确切行为是什么?它是否仍在运行,并使用getResponse()返回响应?

最佳答案

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.



the javadoc of the javax.servlet.AsyncContext interface:

In the event that an asynchronous operation has timed out, the container must run through these steps:

  1. Invoke, at their onTimeout method, all AsyncListener instances registered with the ServletRequest on which the asynchronous operation was initiated.
  2. 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.
  3. 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

关于jakarta-ee - 超时后的JavaEE 6 AsyncContext行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15447666/

相关文章:

java - JMS 消息确认超时?

java - Java 应用程序中每个类的成本 - 更少的大类或几个更小的类

javascript - 在 Javascript 中创建用于采样数据的时间戳对象数组?

javascript - 我应该在 Javascript 的回调函数中使用 '' return"吗?

rest - 带队列的长时间运行的 REST API

c# - NetworkStream ReadAsync取消

java - 在表中添加相同的组件?

java - 使用 JPA 返回两个结果集

java - JPA 中的两个实体之间是否可以有多个关系?

java - 动态变量和异步