Recently I was thinking about the thread security issue of JSP and servlet.
According to my understanding, the instance variables in the servlet are non-thread-safe (the variables are on the stack), while the service, dopost, the variables declared in the doget method are thread-safe (the variables are on the stack ). Only one servlet instance is maintained in the Web server, and a new thread is added for processing each client connection. So is thread security a question about thread security of class variables in multi-thread classes?
We know that every new thread generates a new instance variable in the multi-threaded class, so servlet is unlikely to be an instance variable in the Thread class. Of course, it is not like a parameter variable or a temporary variable. Is the servlet class a static variable in this multi-threaded class?
In addition, the action class in the Struts framework is not thread-safe. As far as I know, the actionservlet class will perform some delegate actions in the action. Can this be understood: In the setlvet-based Web server, all servlet or servlet delegate-based class variables are not thread-safe, the only safe thing is that the class method is not a temporary variable of the class. If there is a class variable in the Temporary Variable, this rule is recursive.