Solved

Significance of load-on-startup in servlet

Posted on 2016-07-27
2
31 Views
Last Modified: 2016-08-11
HI,
I have the following spring web.xml file :
<web-app version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<display-name>Spring MVC Application</display-name>

    <servlet>
		<servlet-name>mvc-dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>mvc-dispatcher</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

Open in new window


What does <load-on-startup>1</load-on-startup> means. I tried removing it and also replacing 1 with 0. But my controller worked properly as before

Thanks
0
Comment
Question by:Rohit Bajaj
2 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 41732188
Basically, it just controls WHEN the servlet gets loaded and initialised. If that element is present (and has a value >= 0) then the web container will load and initialise the servlet when the container itself has started.

If the element is NOT present (or is there but has a value < 0) then the web container is free to start it whenever it feels like it, probably right when the first request comes in the matches the URL pattern.

That's why you didn't see any difference, the servlet still gets loaded, it's just that WHEN it got loaded would be different. The only thing that you may have seen when omitting that element is a slight delay after your first request before the response was received due to the time taken to load the servlet.


Note: if you do include that element, then the number that you put there controls the order of servlet start up when there are multiple servlets defined.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question