Whether action is thread safe or unsafe. Let's see if servlet is thread safe. Actions are inherited from servlet.
Let's take a look at the explanations of other materials:
JSP is executed in multiple threads by default. This is different from ASP, PHP, Perl, and other scripting languages. It is also one of its advantages. However, if you do not pay attention to the synchronization problem in multiple threads, make the written JSPProgramThere are hard-to-find errors.
Multithreading in JSP:
When the client requests a JSP file for the first time, the server compiles the JSP file into a class file, creates an instance of this class, and then creates a thread to process client requests. If multiple clients request the JSP file at the same time, the server creates multiple threads. Each client request corresponds to a thread. Multi-threaded execution can greatly reduce system resource requirements and increase the concurrency and response time of the system. The possible variables in JSP are described as follows:
Instance variables
Instance variables are allocated in the heap and shared by all the threads of the instance, so they are not thread-safe.
Eight class variables provided by the JSP system
The out, request, response, session, config, page, and pageconxt used in JSP are thread-safe and application is used throughout the system, so they are not thread-safe.
Local variable
Local variables are allocated in the stack. Because each thread has its own stack space, it is thread-safe.
Static class
Static classes can be directly used without being instantiated, and are not thread-safe.
External resources:
In a program, multiple threads or processes may simultaneously operate on the same resource (for example, multiple threads or processes simultaneously perform write operations on a file). At this time, pay attention to the synchronization problem.
Make it run in a single thread mode. At this time, there is still only one instance, and all client requests are executed in serial mode. This will reduce the system performance
The final solution is: Do not use instance variables in action
Forwarded from: http://longzhu007.javaeye.com/blog/327190