关于Java:设计问题-Servlet中异步请求的线程安全性

Design issue - thread safety of Async requests in servlets

Servlet 3.0规范的

2.3.3.4部分读取-

Other than the startAsync and complete methods, implementations of the
request and response objects are not guaranteed to be thread safe.
This means that they should either only be used within the scope of
the request handling thread or the application must ensure that
access to the request and response objects are thread safe.

我正在使用码头,我的问题是-

我的要求是在正在处理请求的异步线程中读取请求的ServletInputStream。现在,如果我要阅读http标头等,这将很容易。在启动异步并传递到线程之前,我可以阅读它们。

但是,在我的情况下,我需要使用ServletInputStream,因为在传递到处理线程之前,我不想缓冲内容。

有没有办法可以解决这个问题?或者,如果我只是将ServletInputStream的引用传递给处理线程,那还好吗?


只要确保在任何一次仅从ServletInputStream读取一个线程,您就可以了。