Don't confuse thread safety with the pass-by-reference concept.
You only get one thread per request, so request attributes are thread safe.
A good workman is known by his tools.
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 81
posted
0
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.
Implementations of the request and response objects are not guaranteed to be thread safe. This means that they should only be used within the scope of the request handling thread. References to the request and response objects must not be given to objects executing in other threads as the resulting behavior may be nondeterministic.
-- SRV. 2.3.3.3.
For exam answer should be yes. I have seen some questions in mock exams with this answer, and HFSJ also mentions this.
Piyush
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 81
posted
0
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.
thanks Piyush service method is thread safe for the exam purpose correct?
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
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.
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 81
posted
0
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.
i got it. but everything inside a service method is thread-safe for the exam purposes.??
thanks..
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
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.
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 81
posted
0
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.
a question like this is what i mean.
which variable is thread safe.
1). local variables [is the one you declare in the service method right??]
2). session attributes.
3). request attributes
4). context attributes.
my answer would be.. 1 and 3..
is that correct... no in the real life but in the exam question they assume they are thread safe...[request and service method]..
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.
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.
Also see the HFSJ page 204 which says:
Only Request attributes and local variables are thread-safe!
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 81
posted
0
Piyush Joshi wrote:
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.
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.
Also see the HFSJ page 204 which says:
Only Request attributes and local variables are thread-safe!
Thanks Piyush i will. best regards from Venezuela.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.