好像that some servlet containers在请求之间重用 HttpServletRequest
(或更一般地说,ServletRequest
)实例。
问题:
有人可以指出servlet 规范定义此行为(或引用此类实例的有效性规则)吗? p>
最佳答案
它没有在 Servlet API 中定义。这是一个实现细节。
在 3.11 中用于请求对象(在 5.6 中用于响应对象)
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
不是必需的,但经常使用。
规范(参见第 2.3.3 章)中的内容是单线程模型。一个请求,一个线程。这允许清理和重用请求。
关于java - HttpServletRequest 重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25626986/