wood burning stoves 2.0*
The moose likes Servlets and the fly likes Why is my servlet loaded twice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why is my servlet loaded twice?" Watch "Why is my servlet loaded twice?" New topic
Author

Why is my servlet loaded twice?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I have my servlet set to:
<load-on-startup>1</load-on-startup>
and it prints out "Loaded!" when it's loaded. This prints TWICE when I start up the server - why is this? (I'm using tomcat 3.2.3 if it's only with that servlet engine that this occurs)
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Robert
It may be that the servlet container created more than one instance of your servlet. I believe it may do this if you implement the SingleThreadModel interface, or under some or other condition where it determines that having only one servlet instance to service requests may degrade overall performance.
Mark.
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
On further investigation, it appears the container may create multiple servlet instances only if the servlet implements the SingleThreadModel interface.
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Interesting!
1. How does the SingleThreadedModel vs the alternative affect everything? (for example static variables)
2. How do I set the thread model to use?
David Peterson
author
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
I have the same issue. My servlet does not implement SingleThreadModel, so I don't think that's the reason in this case.
David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is my servlet loaded twice?
 
Similar Threads
JSP load on startup
cannot load servlet name :
How can I verify the ocurrence of <load-on-startup> Servlet? (TOMCAT)
load-on-startup doubt ...
Regarding the init() methods