Solved

Significance of load-on-startup in servlet

Posted on 2016-07-27
2
28 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connect to IP Camera using Java 4 160
Which is the latest version of Apache Tomcatl 3 50
Core Java. What output will be and why ? 6 66
eclipse shortcuts 9 45
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now