aspose file tools*
The moose likes Servlets and the fly likes Get session object from session id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get session object from session id" Watch "Get session object from session id" New topic
Author

Get session object from session id

Cindy Smith
Greenhorn

Joined: Nov 26, 2007
Posts: 18
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

Joined: Jan 10, 2002
Posts: 61221
    
  66

Your explanation mixes the application context and the session. To which are you actually referring?

But to either, yes. There can be contention issues.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Cindy Smith
Greenhorn

Joined: Nov 26, 2007
Posts: 18
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

Joined: Sep 07, 2008
Posts: 688

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..


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get session object from session id