Single-Thread and Multithread Issues
Servlets are inherently multithreaded, so a single instance of a servlet may be invoked from multiple requests threads. However, the servlet container supports a simple mechanism for serializing access to a particular servlet. If a servlet element in the web.xml file contains the attribute single-thread="true", the servlet container only allows one thread at a time to enter the servlet. If a new request arrives for the servlet while a thread is active in the servlet, the new request waits until the active thread leaves the servlet. This slows down the servlet, and may even slow down other servlets in the Agent if many threads are waiting. The container does not prevent threads from entering other instances of the servlet, and other threads in the container remain active when a thread enters a single-thread access servlet.
The servlet element below specifies that only one thread at a time may enter the singleServlet instance.
<servlet single-thread="true">
<servlet-name>singleServlet</servlet-name>
<servlet-class>sync.createSingleServlet</servlet-class>
...
</servlet>
Single-thread access can be useful for debugging purposes or as a temporary wrapper around an application with threading problems. However, because single-thread access does not completely solve threading issues and can reduce performance for the overall servlet container, it may be unsuitable for production applications. Configuring multiple containers, each with a single thread, may offer better performance, as described in
Configuring Multiple Single-Thread Servlet Containers.