java - HttpServletRequest 重用

标签 java tomcat servlets web-applications application-server

好像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/

相关文章:

java - 在 Netbeans 中运行采用未定义数量输入的代码

java - Spring Boot Tomcat 无法在特定端口上启动

java - 使用 HTML 5 和 servlet 的视频

java - Servlet 在程序中的计数

javax.mail.MessagingException : Could not connect to SMTP host locally via netbeans

带有 Java 8 的 Tomcat 6 给出 JSP 编译错误

java - 为什么 avro 无法从 .avro 文件中获取架构?

java - Weblogic服务器: Copy files to shared location within network using Java

java - 将选定的行从数据表发送到操作方法?

java - Spring Boot 中 MultipartFile 的最大限制