In the java servlet life cycle, the first phase is called ‘Creation and intialization’.
The java servlet container first creates the servlet instance and then executes the init() method. This initialization can be done in three ways. The default way is that, the java servlet is initialized when the servlet is called for the first time. This type of servlet initialization is called lazy loading.
The other way is through the <load-on-startup>non-zero-integer</load-on-startup> tag using the deployment descriptor web.xml. This makes the java servlet to be loaded and initialized when the server starts. This process of loading a java servlet before receiving any request is called preloading or preinitialization of a servlet.
Servlet are loaded in the order of number(non-zero-integer) specified. That is, lower(example: 1) the load-on-startup value is loaded first and then servlet with higher values are loaded.
Example usage:
<servlet>
<servlet-name>Servlet-URL</servlet-name>
<servlet-class>com.javapapers.Servlet-Class</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>














Thanks for all the answers.Answers are complete and specific.These are very helpful.
Madhuparna Mukherjee on April 25th, 2010 4:25 amThis tutorial is concise and helpful for last minute revision.
satya samal on May 19th, 2010 8:50 amThx
xd on June 30th, 2010 5:44 pm“This initialization can be done in three ways.”…. 01. Lazy loading (default) 02. Using and 03. ?
dkjena4u on October 23rd, 2010 5:10 pmInitialization can be done in three ways.
1. Lazy Loading(when servlet gets its first request then instantiate.)
2. (Non zero integet)
[As per resin if value 0 or +ve integer then load lower value first. If the value is negative or unspecified, then the container can load the servlet at anytime during startup.]
What is third way to instantiate servlet?
Dipraj on December 10th, 2010 6:55 ammy question is that-how can we call a servelet?
See, I make a servelet “HelloWorld” and I want to show a message like ‘hello world’ than how I call this servelet?
Can I instantiate a swrvelet on jsp page?
yatish sharma on May 29th, 2011 5:47 amVery good article for a new person like me to learn these things
Justin on June 2nd, 2011 6:46 amon which basis servlet is called if there are more than one servlet in your application
Vishal Singh on July 4th, 2011 10:56 amthankQ…………..very nice
suresh on November 5th, 2011 6:27 pmzero will do the same as positive number.
Anonymous on January 31st, 2012 6:30 pmhi joe, this is very useful information,
thanks for this
but my doubt is where is the third way, if you have answer please update it
you mentioned above like “This initialization can be done in three ways”
so asked, if there is no third way then can you please update in this answer
thanks
akbar on March 8th, 2012 8:19 pmwhat is servlet
chimu on March 17th, 2012 3:32 pmNice blog….learned new things
Tuhin on March 21st, 2012 11:43 amGreat Explanation. Thank you Joe, and
Shashi Kanth on March 22nd, 2012 3:40 pmmissing 3rd way of initialization.
Very Helpful
Jp on May 21st, 2012 9:15 pm