It may be true that session attributes are not thread-safe, but that is extremely unimportant. The normal problem with synchronization in servlets is with two different users accessing the same servlet. Those two users will normally have different sessions, so there is no synchronization issue with the two different sessions there. It's possible that those two users are in fact the same user who opened two browser windows and clicked on things very fast to make two simultaneous requests to the same servlet. But I would not do anything in my programming to allow for that remote possibility.
HttpSession session=request.getSession(); synchronize(session) { //setAttributes in the session object //getAttributes from the session object }
没研究过struts2,也不用它.我也问过别人(当然比我厉害的).java web需要作到线程安全吗?他说不需要 HttpSession session=request.getSession(); synchronize(session) { //setAttributes in the session object //getAttributes from the session object }
24,923
社区成员
16,548
社区内容
加载中
试试用AI创作助手写篇文章吧