This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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!
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..