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

Thread Safety

 
chandana sapparapu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following spec is clear for me.
SRV.2.3.3.3 Thread Safety
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.


My question is does a scenario arise often in practice? And if so, could you let me know when.

Thanks.
 
Tejas Bavishi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by chandana sapparapu:
The following spec is clear for me.


My question is does a scenario arise often in practice? And if so, could you let me know when.

Thanks.



Well, my understanding is that spec describes this point to warn developers not to keep references to the request/response objects in different request handling threads. If you want to try this, then imagine someone saving a reference to the request/response object in the session object, and then trying to access the these objects in different requests handling threads. I am not sure what the behaviour will be as I have not tried this before. But the results will definitely be not as expected.

I guess other javaranchers may explain this in a better way.

Thanks
Tejas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic