The load-on-startup component of web-app loads the servlet at the time of deployment or server start if value is positive. It's also known as pre-initialization of servlets.
Both positive and negative values for the servlet can be passed.
As you can see, the servlet is loaded initially. meaning it consumes longer initially. Servlets are started to be loaded at project deployment time or when the server starts, If you define the load-on-startup in web.xml. So, it will take less time to give response to the initial request.
If you pass the positive value, the lower integer value servlet is going to be loaded before the upper integer value servlet. To put it in another way, the container loads the servlets in ascending integer values. The 0 values are going to be loaded first then 1, 2, 3 then on.
Here is one example given below that can make you understand this:
<web-app> .... <servlet> <servlet-name>servlet1</servlet-name> <servlet-class>com.intellinuts.FirstServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet> <servlet-name>servlet2</servlet-name> <servlet-class>com.intellinuts.SecondServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> ... </web-app>
Both servlets will be loaded at the time of project deployment or server start which are explained above. Firstly, servlet1 is loaded and after that servlet2
Servlet will be loaded at the time of request, at first request. if you pass the negative value.