File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Object ArrayList Attribute and Thread Saftey Issue

 
James Ellis
Ranch Hand
Posts: 205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic