All, For better understanding the Attributes
of HttpSession
thread issue.I wrote some test code for it ,I had thought the below code should be thread-safety way to go.
HttpSession session = request.getSession();
synchronized (session) {
Integer n = (Integer) session.getAttribute("foo");
session.setAttribute("foo", (n == null) ? 1 : n + 1);
}
But Actually the Answer of it tell me It is not . I just can't understand it ,In my opinion, I thought the session is the conversion between one client and the server .Is there any thread issue for this situation? If there is , Please tell me in which case this code is not thread-safety. thanks.