Servlet thread pool vs Servlet instance pool - by the web container

5.9k views Asked by At

I understand that web containers like jboss have a parameter to mention the number of threads of the servlet to create, which is the maximum number of threads the container can create to run on a Single instance of the servlet.

My question however is, is there a way to specify the number of instances of a servlet to be created? If yes, what is the purpose? The need for this may be to handle requests, when say a thread or threads running on the single instance somehow corrupt that servlet data or destroy() it - Redundancy purposes.

1

There are 1 answers

1
Ernesto Campohermoso On BEST ANSWER

EDIT: Watch out ! As of Servlet Specification 2.4, interface javax.servlet.SingleThreadModel is deprecated, with no direct replacement.

The specification is unclear as to whether containers should then create several instances of the same servlet, or always only a single instance.


From Servlet Specification 2.4 http://download.oracle.com/otndocs/jcp/servlet-2.4-fr-spec-oth-JSpec/

SRV.2.2 Number of Instances

The servlet declaration which is part of the deployment descriptor of theWeb application containing the servlet, as described in Chapter SRV.13, “Deployment Descriptor”, controls how the servlet container provides instances of the servlet. For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration. However, for a servlet implementing the SingleThreadModel interface, the servlet container may instantiate multiple instances to handle a heavy request load and serialize requests to a particular instance.

In the case where a servlet was deployed as part of an application marked in the deployment descriptor as distributable, a container may have only one instance per servlet declaration per Java Virtual Machine (JVMTM). However, if the servlet in a distributable application implements the SingleThreadModel interface, the container may instantiate multiple instances of that servlet in each JVM of the container.

You can found in the document more information about Single Thread Model