Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what does <load-on-startup> do in web.xml ?

 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does <load-on-startup> in the below code do ?



Following are my queries:-
Ques1 What does 1 signifies ?
Ques2 Does it load ActionServlet(org.apache.struts.action.ActionServlet) or does it load Struts-Config.xml file ?
Ques3 What if i write something like this
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are not loaded until they are first accessed by a request. This may result in a slow access time for the first user. The load-on-startup tag allows you to force the container to load and initialize the servlet at startup.

1. The "1" is used to give a startup order when other servlet are also using load-on-startup. From the servet specification:

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.


2. It initializes ActionServlet, which reads your configuration file

3. Try it But now you should already have an idea of what's going to happen.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Servlets are not loaded until they are first accessed by a request. This may result in a slow access time for the first user. The load-on-startup tag allows you to force the container to load and initialize the servlet at startup.

1. The "1" is used to give a startup order when other servlet are also using load-on-startup. From the servet specification:

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.


2. It initializes ActionServlet, which reads your configuration file

3. Try it But now you should already have an idea of what's going to happen.




Chris, my next question, now what happens if
i put a negative integer say -1
or, i put zero o
or i just remove the this tag completely ???

Thanks in advance
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read again:
If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Read again:
If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses.


Thanks, i just skipped that, my mistake.

ok, let me summarizes it once again,
for 0 or greater than 0, the container will load the servlet when the server gets started and when the element tag is not present or for negative integers, the container will only load the servlet when the 1st request comes to it and not during server startup., am i right ???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. To be more precise, if it is negative or more present, the container is free to load it whenever it wants. Might be at startup. Might be at the first request. If you want to ensure that it is loaded at startup, you'll have to use <load-on-startup> with a value >= 0.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Yes. To be more precise, if it is negative or more present, the container is free to load it whenever it wants. Might be at startup. Might be at the first request. If you want to ensure that it is loaded at startup, you'll have to use <load-on-startup> with a value >= 0.


thanks alot.....appreciated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic