- When multiple clients access the same servlet concurrently, the Web server creates a thread for each request and invokes the Servlet's service method on that thread, so if the same resource is manipulated within the service method, There may be a thread safety issue
- If a servlet implements the Singlethreadmodel interface, the Servlect engine invokes its service method in single-threaded mode
- There is no task method defined within the Singlethreadmodel interface , as long as the declaration of implementing the Singlethreadmodel interface is added to the definition of the servlet class
- The Servlet,servlet engine, which implements the Singlethreadmodel interface , still supports multithreaded concurrent access to the servlet by producing multiple servlet instance objects . Each concurrent thread invokes a separate Servlet instance object, respectively
- implementing the Singlethreadmodel interface does not really address the thread safety of the servlet, because the servlet engine creates multiple servlet instance objects. The real solution to multithreading security is that a Servlet instance object is called concurrently by multiple threads. In servlet API 2.4, Singlethreadmodel has been marked as deprecated (obsolete)
therefore, to solve the thread safety problem, it is best to use synchronized
servlet Thread Safety