Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet instances

 
Mathew Sam
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will it be same servlet instance servicing the request if access it through either servlet class name or servlet-name in web.xml or url-pattern defined in web.xml ?
regards,
Sam
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mathew,
It will be different instance. In first, when you start your web server, the web-server will create one servlet instance for the servlet that you defined in your web.xml.
But if your want to acces to your servlet with the package's name, then your 're creating an other instance of your servlet. If you had defined parameters for your servlet in web.xml then you won't be able to access to these parameters because you had defined these parameters for the servlet that you had defined in web.xml not for the servlet with the package's name
I hope it can help you.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SRV.2.2 Number of Instances
The servlet declaration which is part of the deployment descriptor of the web 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 virtual machine (VM). However, if the servlet in a distributable application implements the SingleThreadModel interface, the container may instantiate multiple instances of that servlet in each VM of the container.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic