Solved

Significance of load-on-startup in servlet

Posted on 2016-07-27
2
25 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help refactoring a java code 8 53
userCompare  challenge 3 61
What is JNDI datasource in spring 1 36
base64 decode encode 12 96
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now