How many instances are created for a HTTP servlet

后端 未结 2 808
攒了一身酷
攒了一身酷 2021-01-04 04:15

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

A web server such as Tomcat

相关标签:
2条回答
  • 2021-01-04 04:49

    by default servlets are intrinsic multithreaded. so only single instance be created and will be accessed by multiple threads.

    0 讨论(0)
  • 2021-01-04 04:53

    The Servlet Specification states

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

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

    0 讨论(0)
提交回复
热议问题