• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Request Attributes Thread Safe?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are request scoped attributes thread safe?

I originally thought they were until I read an article on the Internet which seems to have confused me! Can anyone clarify this for me?

Thanks!!
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Request attributes are thread safe until and unless you are accessing the attribute object from other part of your application.
 
Andrew Rigsby
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!

So, if asked in the SCWCD exam whether request scoped attributes are thread safe the answer is 'Yes'.

Do you need to consider the fact that a reference to the request attribute may be being used in another part of the application in the exam?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

what you should do on the exam? yes or not?-

best regards.
 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

best regards.
 
Piyush Joshi
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic