https://bz.apache.org/bugzilla/show_bug.cgi?id=58411

--- Comment #13 from Christopher Schultz <ch...@christopherschultz.net> ---
(In reply to Remy Maucherat from comment #11)
> The thread safety issue actually came up fairly often in the past. And this
> doesn't make sense, why would it be partially synced ?
> 
> The specification is perfectly explicit about it (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.
> If a thread created by the application uses the container-managed objects,
> such as the
> request or response object, those objects must be accessed only within the
> object’s
> life cycle as defined in sections Section 3.12, “Lifetime of the Request
> Object” on
> page 3-31and Section 5.7, “Lifetime of the Response Object” on page 5-50
> respectively. Be aware that other than the startAsync , and complete
> methods, the
> request and response objects are not thread safe. If those objects were
> accessed in the
> multiple threads, the access should be synchronized or be done through a
> wrapper
> to add the thread safety, for instance, synchronizing the call of the
> methods to access
> the request attribute, or using a local output stream for the response
> object within a
> thread."
> 
> Anyway, if despite the last sentence, you want to fix this "issue", go ahead
> :)

I would argue that the spec here limits its scope to the "request and response
objects" themselves. The servlet spec doesn't cover java.io.Writer, and
therefore the servlet spec is silent on the thread safety of the PrintWriter
returned by response.getWriter.

It may be worth noting that ServletOutputStream and OutputStream seem to say
nothing about thread safety, implying that one can use response.getOutputStream
to avoid the costs of synchronization if necessary.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to