This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes When a servlet is instantiated? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "When a servlet is instantiated?" Watch "When a servlet is instantiated?" New topic
Author

When a servlet is instantiated?

Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
Hi All,
Suppose, not defining <load-on-startup> in the web.xml.
The servlet instance is created when servlet container starts up or it's not created until a request for this servlet comes?

Thanks a lot!

Hai
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Without a <load-on-startup> configuration setting, the servlet is created the first time it is requested. If your Servlet initialization is resource intensive (say if it needs to create a large number of support objects) then the first user/client to access that Servlet will experience a delay. In such cases, you should use the <load-on-startup>. You only need to define a number -- such as <load-on-startup>1</load-on-startup> -- if the initialization order of your Servlets is important. If not, you can simply use <load-on-startup/>.
[ June 03, 2004: Message edited by: Mark Vedder ]
Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
Mark,
Thanks a lot to clear my confusion.

Hai
Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200
Following are the exact words picked from Servlet 2.3 specification
"The servlet container is responsible for loading and instantiating servlets. The loading and instantiation can occur when the container is started, or delayed until the container determines the servlet is needed to service a request.".

Hope this clears the confusion
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When a servlet is instantiated?
 
Similar Threads
no "war" file created when we deploy a servlet through tomcat ?
servlet lifecycle question
Servlet loading on application startup
How to find if the servlet is newly created or it was already existing
Servlet loading and servlet instacne