aspose file tools*
The moose likes Servlets and the fly likes Multiple 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 "Multiple Instances of a Servlet" Watch "Multiple Instances of a Servlet" New topic
Author

Multiple Instances of a Servlet

Abhinay Verma
Greenhorn

Joined: Dec 13, 2004
Posts: 24
Hi
Is there any way to have multiple instances of a servlet even if we are not implementing SingleThreadModel ?

Please let me know if there is a way.

Thanks in advance,
Abhi
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why would you want multiple instances of a servlet?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The answer is yes, you can. Ben's question is more interesting though
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
You will have a separate instance of a servlet for each distinct entry in a web.xml deployment descriptor. I suppose you could have the same servlet code playing dozens of different roles in the same or different "web applications".
Sometimes people do this by accident and we get the "why do I see two init() messages from my servlet" question.
Bill
Abhinay Verma
Greenhorn

Joined: Dec 13, 2004
Posts: 24
Thanks to you all for the quick help.

Thanks a lot, William
Your post has answered all my queries about this issue.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Abhinay,

You never told us why.
Abhinay Verma
Greenhorn

Joined: Dec 13, 2004
Posts: 24
Ben,
I was discussing some concepts with my friends who are planning for SCWCD certification and this was one of the doubts. This was the only reason I asked this question
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Abhinay,
Thanks
Raja gopal Y
Greenhorn

Joined: Mar 08, 2005
Posts: 15
The Easiest way is to use the

<load-on-startup>

tag of web.xml

Any comments !!!


CHEERS !!!<br /> <br />RAJAGOPAL Y
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Instances of a Servlet