Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Load On Startup

 
Sean Hetfield
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding Load On Startup:

Servlet A has Load On Startup 1

Servlet B has Load On Startup 2

Based on above inforamtion, which one of the following is right?

1) Container Loads Servlet A and calls the init() method on Servlet A, Container loads the servlet B and calls the init() method on servlet B

2) Container Loads Servlet A and then Loads Servlet B, Continer calls the init() method on Servlet A and then calls the init() method on Servlet B


Thanks

Sean
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question though!

I found following:
Some content from the Servlet Specification:


Instantiate an instance of each servlet identified by a <servlet> element that includes a <load-on-startup> element in the order defined by the
load-on-startup element values, and call each servlet instance�s init()
method.



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.



Thanks,
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the question Sean, and thanks for the answer Chandra
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if two servlets have the same <load-on-startup> value ... which will be loaded first ?? I guess the one which appears first in the DTD ?? I am i close ??

Thanks
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The order of loading the servlets is one way dependent on the entries in the web.xml as you give.

If two or more servlets have the same value of <load-on-startup> element, then it purely depends on the container!

As per the Servlet 2.4 spec section SRV.13.3 Deployment Descriptor, it says,


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
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.



Also in subsection 10.servlet Element of the section SRV 13.4 Deployment Descriptor Diagram, it confirms the same as


The container may choose the order of loading of
servlets with the same load-on-startup value.


Hope this clears!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question. From where did you get this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic