Issue Details (XML | Word | Printable)

Key: SERVLET_SPEC-41
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Rajiv Mordani
Reporter: rstoyanchev
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
servlet-spec

Clarify the limitations on using the request and response from an application thread

Created: 04/Jun/12 08:59 PM   Updated: 19/Jul/12 01:29 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Tags:
Participants: gregwilkins, Rajiv Mordani and rstoyanchev


 Description  « Hide

Section 2.3.3.4 of the Servlet 3.0 spec gives this advice on thread safety with regards to using the request and response objects in an async scenario:

"... 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."

This makes it clear they're not thread safe but also gives the impression that as long as access to these objects is synchronized, they can be used. However, in this servlet-spec user discussion, Greg Wilkins suggests there are a number of request methods that should probably never be used from an async thread including the context path, servlet path, path info, request URI, getting a RequestDispatcher, accessing the session (and possibly others) since their values may change.

Not surprisingly the behavior of Servlet containers varies. The scenario mentioned by Greg actually works in Tomcat and Glassfish potentially leading one to believe it's portable code. Even if one didn't intend on switching containers or didn't care about writing portable code, it's still not clear if the request and response can be used reliably or if they just happen to work in some scenarios.

The spec should make it clear what parts of the request and response should not be used from an application thread in an async scenario.