multithreading - Servlet 线程池 vs Servlet 实例池 - 通过 Web 容器

标签 multithreading servlets jboss websphere web-container

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

但是我的问题是,有没有办法指定要创建的 servlet 实例的数量?如果是,目的是什么?当单个实例上运行的一个或多个线程以某种方式损坏该 servlet 数据或 destroy() 它时,这种需要可能是为了处理请求 - 冗余目的。

最佳答案

编辑:小心!从 Servlet 规范 2.4 开始,接口(interface) javax.servlet.SingleThreadModel已弃用,没有直接替代。

规范并不清楚容器是否应该创建同一个 servlet 的多个实例,或者始终只创建一个实例。


来自 Servlet 规范 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.

您可以在文档中找到有关单线程模型的更多信息

关于multithreading - Servlet 线程池 vs Servlet 实例池 - 通过 Web 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7826452/

相关文章:

java - 在 JBoss 7 访问日志中指定毫秒

ios - 你能在没有死锁的情况下从并发线程调用 dispatch_sync 吗?

c - 与共享变量并行运行 2 个线程

linux - 线程退出但仍保持互斥

java - 在 Servlet 中读取序列化对象时出现 EOFException

Java Servlet : why is PrintWriter.lush() 不刷新?

java - 在 JBoss 7.1.1 的这个模块中已经定义了一个名为 'XXX' 的组件

multithreading - 由TPanel父级创建的TButton的TThread创建

java - 我如何知道 HttpServletRequest 是否受 <security-constraint> 约束?

java - 带有 hibernate validator 5.1.0.Final 的 jboss 上的 NoSuchMethodError