gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:49:51 24 4
gpt4 key购买 nike

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

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

最佳答案

编辑 : 小心 !从 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com