Show TOC Start of Content Area

Background documentation Threadsafe Servlets  Locate the document in its SAP Library structure

Caution

Be aware that use of SingleThreadModel interface is deprecated since version 2.4 of the servlet specification.

It is possible that multiple threads can be executed in the service method of your servlet. This may cause inconsistencies if the servlet uses any in-memory data, such as instance or class variables.

To ensure that no two or more threads are executed in the service method of your servlet at the same time, it must implement the SingleThreadModel interface. The AS Java’s Web Container does not create a pool of instances of such a servlet; the instance of the servlet is single per servlet declaration. The Web Container just synchronizes the access to the servlet, which guarantees that no two threads can access its service method concurrently.

However, implementing the SingleThreadModel does not solve the synchronization problems that may occur if multiple servlet instances access the same shared resource outside the servlet class (for example, a shared file, or database access). Remember that several instances of the same servlet can exist if there are few servlets defined in the Web descriptor with the same classes. In this case, you must control access to those external resources using the synchronization techniques of the Java programming language.

 

 

End of Content Area