This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session Object ArrayList Attribute and Thread Saftey Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Object ArrayList Attribute and Thread Saftey Issue" Watch "Session Object ArrayList Attribute and Thread Saftey Issue" New topic
Author

Session Object ArrayList Attribute and Thread Saftey Issue

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I have this issue which only appears in production. I suspect a threading issue since it only appears under high load.

In my code there is a Requirements bean:



...that is set into session by a servlet. Right after that servlet sets that bean into session it includes a JSP page which has embedded Ajax which upon loading makes an Ajax call back to the server. This Ajax call calls another servlet on the server which references the Requirements object that was put into session. Once in a while that Requirements object is missing data (or possibly completely missing).

Here is the pseudocode:



Two Questions:
1) When you set a session attribute from a servlet, will that method call "setAttribute" guarantee to finish before the servlet's doPost?
2) When you add members to an ArrayList (rolesToAdd), are these guaranteed to be added by the time the ArrayList is added to the requirements object (which is then added itself to session)?

I know that ArrayList is not synchronized...but I'm not sure if that means that calls to ArrayList.add("obj") are guaranteed to finish before caller moves on. I have the same concern about session.setAttribute, not sure if calls to setAttribute are guaranteed to finish before caller moves on.
[ July 26, 2008: Message edited by: James Ellis ]
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

FYI to those responding to this thread, it is also being discussed on the forum.sun.com forums: Java Servlet - Session Scope Attribute ArrayList Threading Question


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Object ArrayList Attribute and Thread Saftey Issue
 
Similar Threads
Session time-out with AJAX
Principals??
@RolesAllowed not affecting calls to my EJB3 session bean method?
Problem in securing EJB modules
Jquery ajax issue