A good workman is known by his tools.
Marc Peabody wrote:They are thread safe.
Don't confuse thread safety with the pass-by-reference concept.
You only get one thread per request, so request attributes are thread safe.
Piyush
Piyush Joshi wrote:For exam answer should be yes. I have seen some questions in mock exams with this answer, and HFSJ also mentions this.
Cristian Daniel Ortiz Cuellar wrote:Implementations of the request and response objects are not guaranteed to be thread safe.
Tim Moores wrote:
Cristian Daniel Ortiz Cuellar wrote:Implementations of the request and response objects are not guaranteed to be thread safe.
Note that this topic is about request attributes, not the request and response objects. While it's certainly to pass those objects to other threads, that's almost willfully bad design :-)
A request attribute, OTOH, could be any old object that also exists elsewhere in the web app - for example, as context or session attribute, which would make it not thread-safe.
Tim Moores wrote:I don't know what "the exam purposes" are, but I assume it's supposed to reflect reality - where it is perfectly possible to write thread-unsafe code in a service method. So, nothing inside a service method is thread-safe unless (and until) you ensure that it is.
Please don't over-complicate the simple objective of these type of questions in exam. In these types of questions the "thread" term generally refers to the container initiated threads for servicing client requests. also request attributes refer to simple objects which are not related to any other scopes.Tim Moores wrote:A request attribute, OTOH, could be any old object that also exists elsewhere in the web app - for example, as context or session attribute, which would make it not thread-safe.
Only Request attributes and local variables are thread-safe!
Piyush
Piyush Joshi wrote:
Please don't over-complicate the simple objective of these type of questions in exam. In these types of questions the "thread" term generally refers to the container initiated threads for servicing client requests. also request attributes refer to simple objects which are not related to any other scopes.Tim Moores wrote:A request attribute, OTOH, could be any old object that also exists elsewhere in the web app - for example, as context or session attribute, which would make it not thread-safe.
Also see the HFSJ page 204 which says:
Only Request attributes and local variables are thread-safe!
Consider Paul's rocket mass heater. |