?
Solved

Significance of load-on-startup in servlet

Posted on 2016-07-27
2
Medium Priority
?
37 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
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…
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.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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