• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

synchronize session

 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic