Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

load on startup


The load-on-startup element of web-app loads the servlet at the time of deployment or server start if value is positive. It is also known as pre initialization of servlet.

You can pass positive and negative value for the servlet.


Advantage of load-on-startup element

As you know well, servlet is loaded at first request. That means it consumes more time at first request. If you specify the load-on-startup in web.xml, servlet will be loaded at project deployment time or server start. So, it will take less time for responding to first request.


Passing positive value

If you pass the positive value, the lower integer value servlet will be loaded before the higher integer value servlet. In other words, container loads the servlets in ascending integer value. The 0 value will be loaded first then 1, 2, 3 and so on.

Let’s try to understand it by the example given below:

web.xml
  1. <web-app>
  2.  ….
  3.   <servlet>
  4.    <servlet-name>servlet1</servlet-name>
  5.    <servlet-class>com.Kreationnext.FirstServlet</servlet-class>
  6.    <load-on-startup>0</load-on-startup>
  7.   </servlet>
  8.   <servlet>
  9.    <servlet-name>servlet2</servlet-name>
  10.    <servlet-class>com.Kreationnext.SecondServlet</servlet-class>
  11.    <load-on-startup>1</load-on-startup>
  12.   </servlet>
  13.  …
  14. </web-app>

There are defined 2 servlets, both servlets will be loaded at the time of project deployment or server start. But, servlet1 will be loaded first then servlet2.


Passing negative value

If you pass the negative value, servlet will be loaded at request time, at first request.

Comments

comments