Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Safe Sessions  RSS feed

 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you implement the methods of the HttpSessionListener interface, is it always a good idea to ensure that the code is thread safe? I'm thinking, for instance, that if you were to remove a session from a Collection in the sessionDestroyed() method, it's possible that two or more threads may be running that method at the same time.

I presume that if you had to write thread safe code, then you should synchronize the code which accesses the Collection on the HttpSession object (as I won't have thought that the entire method needs to be synchronized).
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I think its needed, make it thread-safe. Not the entire method but just the code accessing the collection.

If you are using ArrayList it means you have to make it threadsafe by yourself. However, unlike ArrayList, Vector is sychronized.

More inputs are welcome.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!