Is sessionCreated() method from a HttpSessionListener automatically synchronized with request.getSession() call? In particular, I would like to know if it is thread safe to set a session attribute in the sessionCreated() method and retrieve the attribute with request.getSession().getAttribute("something") in a servlet?
For example, is it thread-safe to have
@Override
public void sessionCreated(HttpSessionEvent se) {
se.getSession().setAttribute("something", new Something());
}
in a HttpSessionListener, and have
Something something = (Something) request.getSession().getAttribute("something");
synchronized(something){
// do anything with this "something" object
}
inside of a doGet() method of a HttpServlet? The point of my concern is that if this sessionCreated() method is not automatically synchronized with requested.getSession() the value returned by getAttribute("something") can be null.