Hi all,
I am preparing for SCWCD 1.4 and reading
Servlets and JavaServer Pages book by Jayson and Kevin.In the book it is mentioned about
thread safety of session object like below
***********************************************************************
Both the HttpSession object and ServletContext object are shared resouces.The ServletContext object can be accessed by many Servers or
JSP at the same time.The HttpSession object can be accessed at the same time by two different requests from a client.In uses of both objects proper synchronization should be used.
The simplest solution to providing accurate session and application in state is to always wrap access to the associated object in a synchronized block.Listing below demonstrates wrapping a session access using a synchronization block.
User user=new User();
HttpSession session = request.getSession(true);
synchronized(session) {
session.setAttribute("user",user);
}
**********************************************************************
Here my question is why we need to synchronized session object.I think it is already thread safe object . Why I am thinking like this is because request and response objects are always thread safe objects.So here we are getting session from request object. so that doen't that mean session is thread safe object ??
Thanks in advance
Raju