This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Get session object from session id Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56185
    
  13

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

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 676

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Get session object from session id
 
Similar Threads
Passing/Accssing HttpSession to service layer
Who all can access HttpSession and/or its attributes ?
How to block multiple logins of the same user
Filter and Struts
Multiple session objects for multiple login user in the same/ new browser window