Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

request attributes thread-safe !?

 
Bitzu Ma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why request attributes are called thread safe. Here's what I mean:
we can get a request and the container services it... new thread, one servlet instance, no problems so far; but if we can still code the creation of two threads that can each set and get the value of the same request attribute in an unsynchronized manner. I mean, in this case WE (not the container) must synchronize the code that gets/sets that attribute. So that means that request attribute is not thread-safe, right? Or is there something (embarrassingly obvious) I'm missing here?
I know spawning threads in a container is an anti-pattern but still...
 
Ankit Garg
Sheriff
Posts: 9597
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you start threads in your servlet then request attributes are not thread safe. Starting threads in your servlet is useless and highly discouraged (as you said yourself). When we say request attributes are thread-safe, it means its safe from threads started by the container to serve requests...
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!