aspose file tools*
The moose likes Servlets and the fly likes can same servlet have multiple instance in container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can same servlet have multiple instance in container" Watch "can same servlet have multiple instance in container" New topic
Author

can same servlet have multiple instance in container

Pratibha Malhotra
Ranch Hand

Joined: Dec 21, 2003
Posts: 199
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


~ Pratibha Malhotra<br /> <br />Sun Certified Java Programmer<br />SCEA 1.4 (In Progress)<br />~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />"Many of life's failures are people who did not realize how close they were to success when they gave up!!"
Kunaal A Trehan
Ranch Hand

Joined: Feb 04, 2004
Posts: 63
Hi
Yes we can have more than one instance for the servlet.
Rgds
Kunal
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
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.


Kaustubh. Mumbai, India.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

Note that SingleThreadedModel is deprecated and should not be used. Just write your servlets to be thread-safe and get on with it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
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
 
jQuery in Action, 2nd edition
 
subject: can same servlet have multiple instance in container