This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
1. Application (ServletContext) attributes, session(HttpSession) attributes, Servlet Instance variables and Servlet class variables are "not" thread safe.
2. Local variables (variables defined in a servlet methods) and request (ServletRequest) attributes are thread safe.
3. If you implement SingleThreadModel interface in a servlet then you can make Servlet Instance variables also thread safe. (In a JSP you implement SingleThreadModel by specifying page directive <%@ page isThreadSafe="false" %>
Note: SingleThreadModel interface is deprecated in Servlet API 2.4.
Joined: Sep 03, 2005
but if somebody ask u how u make ur servlet/jsp thred safe, not explicitly asking u context, session, request attibute, what will be ur answer.
again the page directive <%@page isThreadSafe="true"%> which is by default say that jsp is thread safe.
Yes, the default is true. But, that is assuming that you will take care of actually making it thread-safe. The most appropriate thing to do is synchronize on any process/logic that will make your servlets (including servlets resulting from JSP) NOT thread-safe. (i.e. any logic that can be accessed by more than one thread simultaneously)
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley