This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronizing on objects in session scope  RSS feed

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you implement synchronization to make sure everything in session scope is thread safe?

Suppose there's an ArrayList in the scope, and a JSP tag grabs an iterator on it and generates a bullet list, while another action is inserting new object into the ArrayList, causing ConcurrentModificationException to be thrown on the JSP side.

Do you consider and try to prevent this scenario?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you should always consider the possibile need to synchronize access to objects in session scope. Consider how many separate "simultaneous" requests may be generated by a browser to render a single page after all.

Compared to all the other time consuming things that go on to handle a request, synchronization overhead is very small.

Bill
 
Lucas Lee
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To handle this kind of problem , the most simple way is to use a thread-safe collection class , such as Vector instead of ArrayList.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!