首页
登录 | 注册

Servlet是单例还是多例?

转自:
https://www.cnblogs.com/softidea/p/7245899.html

在Servlet规范中,对于Servlet单例与多例定义如下:

“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没有被部署在分布式的环境中,一般web.xml中声明的一个Servlet只对应一个实例。
而如果一个Servlet实现了SingleThreadModel接口,就会被初始化多个实例。



2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.010 s.
京ICP备10005923号