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

session - thread safety

 
john abhraham
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I learnt that session is not thread safe. Then can we ever use a session? (Considering that we should also not implement singleThreadModel). Whatever we put in the session can be modified by some other session.Right?
This applies to servlet context etc..all which are not thread safe.

Regards
john
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session may not be Thread safe. A session is just an object at the end of the day, and you can synchronize on it to ensure thread safe semantics when accessing it.

A session allows the server to remember a client when a new request comes in with the same session id. A client certainly can't access stuff in other peoples sessions, so you don't need to worry about that. What can come up is that you can get multiple threads running from the same client. I understand that this is browser and platform dependent. Some will fire up new threads and share a session when you open a new browser (on the same computer) and some won't.

As I understand it, this means that you should synchronise access to the session object to prevent yourself from screwing up your own data.

Please correct me if I'm wrong!

Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic