top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

In Java Servelet Initialization can be done in many ways, do we have any default method to do it?

+1 vote
567 views
In Java Servelet Initialization can be done in many ways, do we have any default method to do it?
posted May 22, 2014 by Varun Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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>
answer May 23, 2014 by Swati Arora
...