Servlet线程池与Servlet实例池-由Web容器 [英] Servlet thread pool vs Servlet instance pool - by the web container

查看:351
本文介绍了Servlet线程池与Servlet实例池-由Web容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解像jboss这样的Web容器都有一个参数来提及要创建的servlet的线程数,这是该容器可以创建以在Servlet的单个实例上运行的最大线程数.

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.

但是我的问题是,有没有一种方法可以指定要创建的servlet的实例数?如果是,目的是什么?当说在单个实例上运行的一个或多个线程以某种方式破坏了该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.

推荐答案

编辑:当心!从Servlet Specification 2.4开始,接口 javax.servlet.SingleThreadModel 已弃用,无法直接替换.

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

关于容器是应该然后创建同一servlet的多个实例,还是始终仅创建一个实例的规范尚不清楚.

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

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

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

SRV.2.2实例数

SRV.2.2 Number of Instances

servlet声明,它是的部署描述符的一部分 包含servlet的Web应用程序,如本章所述 SRV.13,部署描述符",控制servlet容器的方式 提供Servlet的实例.对于未托管在服务器中的servlet 分布式环境(默认),servlet容器必须使用 每个Servlet声明仅一个实例.但是,对于servlet 实现SingleThreadModel接口,即servlet容器 可以实例化多个实例以处理繁重的请求负载,并且 将请求序列化到特定实例.

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.

如果 Servlet是作为应用程序的一部分进行部署的,该应用程序在 部署描述符为可分发的,一个容器可能只有一个 每个Java虚拟机(JVMTM)的每个servlet声明的实例. 但是,如果可分发应用程序中的Servlet实现了 SingleThreadModel接口,容器可以实例化多个 容器的每个JVM中该servlet的实例.

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

这篇关于Servlet线程池与Servlet实例池-由Web容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆