Solved

Significance of load-on-startup in servlet

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordappend challenge 8 246
netstat -ano | find "8000" and taskkill /f /pid 2984 3 112
hibernate example using maven 12 106
jboss 7.1 start up error 1 82
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 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.

737 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