Two Laptop Bag*
The moose likes Servlets and the fly likes Instances of a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Instances of a Servlet" Watch "Instances of a Servlet" New topic
Author

Instances of a Servlet

N Paul
Greenhorn

Joined: Dec 31, 2002
Posts: 1
Is it possible to restrict the number of instances created of a Servlet that is using the SingleThreadModel?
Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
Hi,
I would suspect that it would be a setting specific to an application server (and therefore non-portable). I don't know of a mechanism within the servlet specification to do this.
If you need to limit the access because your servlet is not threadsafe then you are limiting the scalability of your application and the servlet should be redesigned. I've never needed to implement the SingleThreadModel to get my work done.
I hope this helps.
Thanks,
Steve
[ December 31, 2002: Message edited by: Steve Granton ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Paul
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
hey paul,
i don't think you can do it. the question is why would you want to do it? may be there is some other solution for your problem?


Asher Tarnopolski
SCJP,SCWCD
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Try not to use SingleThreadModel.
I wonder if anybody is using it.


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Ruchi Kolla
Greenhorn

Joined: Jan 24, 2002
Posts: 19
SingleThreadModel doesn't gaurentee the single instance by definition itself. If you want to have only single instance don't use SingleThreadModel.
If you don't use Single Thread Model by default the server creates one single instance and makes all requests to that servlet as multiple threads.
If you want to use SingleThreadModel for synchronization purpose use synchronized code inside your servlet rather than using SinglThreadModel.
Hope this help you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instances of a Servlet
 
Similar Threads
Stateless session bean
servlet does not contain main()
Multiple Instances of a Servlet
servlets life cycle
Multiple Servlet Instance?