• 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

Session Object ArrayList Attribute and Thread Saftey Issue

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic