Question of synchronizing HttpSession
posted 10 years ago
So the alternative code you are suggesting isWith this code it is possible for some other thread to call setAttribute("foo", new Integer(22)) after your thread calls setAttribute but before it calls getAttribute. With the original code it is not possible -- at least it is not possible if that other thread is also synchronizing on the session. So there is a difference.