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

查看:27
本文介绍了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 数据或 destroy() 它时 - 冗余目的.

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 规范 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 规范 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实现 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天全站免登陆