When a
Servlet implments SingleThreadModel then the local, instance and request variables are
thread safe.
Therefore, I think I could said the belowing serlvet, which implements SingleThreadModel and has a instance variable, is thread safe, right?
----------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet implements SingleThreadModel {
public
String var; //Instance variable
public doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServeltException{
.....
}
}
----------------------------------------------
But can we say the Servlet is ThreadSafe if it implements SingleThreadModel but has a "class variable"??
Like this:
----------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet implements SingleThreadModel {
static public String var; //class variable
public doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServeltException{
.....
}
}
----------------------------------------------
Is this Servlet is ThreadSafe? Cause I think class variable is never thread-safe.
Thank you.