Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can same servlet have multiple instance in container

 
Pratibha Malhotra
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Single thread model is used to enforce one request accessing servlet at a time .
Servlet Api says, container may decide to have multiple instances of servlet if SingleThreadModel is implemented.
can we have more than one instance of a servlet in a container
 
Kunaal A Trehan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Yes we can have more than one instance for the servlet.
Rgds
Kunal
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet can have more than one instances in the JVM. The number might be configured.
SingleThreadedModel indicats that at a time only one request will be allowed to access the one instance's service() method. Effectively it means that the service() method is synchronized.
Note : There might be more than one instances in SingleThreadedModel and more than one requests serviced. But only one request per instance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that SingleThreadedModel is deprecated and should not be used. Just write your servlets to be thread-safe and get on with it.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To quote from the Servlet API 2.3 - section 2.2
"For a servlet not hosted in a distributed environment (the default) the servlet must use only one instance per servlet declaration."
It then goes on to discuss the exception of the SingleThreadModel.
You really should get a copy of the API to answer these questions - it is the final authority.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic