Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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: 9578
33
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic