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

只愿长相守 提交于 2019-12-02 06:52:35

问题


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:


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



来源:https://stackoverflow.com/questions/7826452/servlet-thread-pool-vs-servlet-instance-pool-by-the-web-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!