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

synchronize session

Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
Hi, I was wondering if we need to synchronize session whenever we make any changes to its attribute values so that concurrent access to the same session will not corrupt the attribute values?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
I think that will depend on the way HttpSession is implemented in your system. Looking at the Tomcat source code, I see that a Hashtable is used to store data, so you would not need to synchronize simple get and set operations, but you would need to synchronize anything more complex, such as getAttributeNames()
To be sure, you should synchronize if your design is such that more than one request will be processed at one time.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by William Brogden:
To be sure, you should synchronize if your design is such that more than one request will be processed at one time.

Whether more than one request will be processed at one time is not just a matter of design. You cannot stop a user from pressing Refresh. If there's anything in your servlet/JSP which may take some time -- intensive computation, database access -- there is a real chance that a single session may see multiple requests at a time.
Moreover, if you've got a site with frames, multiple simultaneous requests are virtually guaranteed. Browsers often open up a couple of connections to load up all the documents in a frameset.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronize session