File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Load On Startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Load On Startup" Watch "Load On Startup" New topic
Author

Load On Startup

Sean Hetfield
Ranch Hand

Joined: Dec 01, 2003
Posts: 83
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

Joined: Feb 28, 2007
Posts: 1707
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,


cmbhatt
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Thanks for the question Sean, and thanks for the answer Chandra


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

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

Joined: Apr 20, 2006
Posts: 3344

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!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

Good question. From where did you get this?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
 
Don't get me started about those stupid light bulbs.
 
subject: Load On Startup