This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get session object from session id

 
Cindy Smith
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the post at the link below and I have a question on it.

http://www.coderanch.com/t/365859/Servlets/java/Get-session-object-from-session

If I store a list of active users in a HashMap in the servlet context, could I have contention issues? Is this a valid concern or is access to the Map synchronized? And if it is not, any suggestions on how to protect the map data from concurrent access? I am thinking multiple threads creating session objects at the same time and adding them to the map could create issues.

Thanks for any comments you may have.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64688
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your explanation mixes the application context and the session. To which are you actually referring?

But to either, yes. There can be contention issues.
 
Cindy Smith
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am referring to the map stored in the servlet context. Since there are contention issues, any suggestions on how to prevent that? If you look into the sample code provided in the posting, there is an HttpSessionListener handling the adding and removing of items to the map. I would like to protect those operations from contention. Thanks!
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your proper implementation code will help you only... There is no way to Synchronize your session and context object. In J2EE application only Request object and local variable are thread safe. SO, if you are facing problem to multiple instance change your context then you can not synchronize it.. you make code properly..

If you look into the sample code provided in the posting, there is an HttpSessionListener handling the adding and removing of items to the map. I would like to protect those operations from contention


yes. using HttpSessionListener you can add and remove each time from map. but synchronization of object will not help you..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic