The session is not thread safe, and none of the get not the set methods are thread guaranteed. Typically, in a servlet container, you should assume that it is in a multi-threaded environment, and no snap-in provided is safe.
This also applies to objects that you store in a session. The session itself will not manipulate the stored object, but you can get the object in another thread and try to manipulate it. It is up to you to check your own code to see if race conditions are possible.
The code sample you have provided is valid, but the problem may exist outside the limited scope of your example. It ensures that when setting up a session there are no conditions, but there is nothing that prevents another thread from overriding the set. If the code in the request depends on a constant value, you may still be in difficulty.
DefLog Mar 05 '09 at 21:27 2009-03-05 21:27
source share