禁用Servlet请求实例的重用



是否可以为每个请求禁用Servlet请求实例的重用?看起来该实例被重复使用了多次(可能是每个TCP会话绑定的?(

您可以在规范中看到的内容:

3.13 Lifetime of the Request Object
Each request object is valid only within the scope of a servlet’s service method, or
within the scope of a filter’s doFilter method, unless the asynchronous processing
is enabled for the component and the startAsync method is invoked on the request
object. In the case where asynchronous processing occurs, the request object remains
valid until complete is invoked on the AsyncContext. Containers commonly recycle
request objects in order to avoid the performance overhead of request object
creation. The developer must be aware that maintaining references to request objects
for which startAsync has not been called outside the scope described above is not
recommended as it may have indeterminate results.
In case of upgrade, the above is still true

容器通常可回收请求对象,以避免请求对象的性能开销创建

它是特定于容器的。

在这种情况下,它是特定于Jetty的。

Jetty在请求之间回收org.eclipse.jetty.server.Request对象。

这是正常的,在Servlet规范的定义范围内,许多容器都这样做。

在容器的调度之外,要小心使用HttpServlet请求/Servlet请求/请求对象。

如果您是从AsyncContext使用它,则应仅在容器调用时使用它,而不是从任何其他点或任何其他线程调用它(除非您100%确定您正确处理了线程,并且准备好从非容器线程使用AsyncContext处理数千种角点情况之一(

最新更新