为HTTP Servlet创建了多少个实例 [英] How many instances are created for a HTTP servlet

查看:93
本文介绍了为HTTP Servlet创建了多少个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览Java Web Services:Up and Running,2nd Edition一书并且发现了一个声明:

I am going through the book for "Java Web Services: Up and Running, 2nd Edition" and came across a statement that says:


像Tomcat这样的Web服务器可以任意实例化多个实例
of一个servlet,虽然这个数字通常很小(例如,1到
4)。 Web服务器本身做出决定。

A web server such as Tomcat can instantiate arbitrarily many instances of a servlet, although the number is typically small (e.g., 1 through 4). The web server itself makes the decision.

所以这意味着如果我创建一个servlet,那么服务器可以创建多个实例但是这个与许多帖子中给出的解释相矛盾,例如,如果我在这篇文章中检查: 10个客户端请求Servlet。如何创建多个servlet实例然后它明确指出:

So it means if I create a servlet then the server can create more than 1 instance but this is in contradiction to the explanation given in many posts for example if I check in this post : "10 clients requests for a Servlet.How many servlet instances are created" then it clearly states that:


只存在一个servlet实例(每个类加载器),每个
请求将在其自己的线程上提供

Only one instance of servlet exist (per classloader) , and each request will be served on its own thread

所以请帮助我理解这一点,服务器是否可以为servlet创建多个实例?

So please help me in understanding this, does a server can create more than 1 instance for a servlet?

推荐答案

Servlet规范声明


对于未托管在分布式环境中的servlet(缺省值),
servlet容器每个servlet
声明必须只使用一个实例。
但是,对于实现
SingleThreadModel 接口的servlet, 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虚拟
机器(JVM)每个servlet声明只有一个实例。但是,如果可分发的
应用程序中的servlet实现 SingleThreadModel 接口,则容器
可以在$的每个JVM中实例化该servlet的多个实例。 b $ b容器。

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 (JVM). 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.

所以这取决于你的部署方式。

So it depends how you are deployed.

根据评论中的建议, SingleThreadModel 已被弃用了很长时间。

As suggested in the comments, SingleThreadModel has been deprecated for a long time.

这篇关于为HTTP Servlet创建了多少个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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