aspose file tools*
The moose likes Servlets and the fly likes <load-on-startup> Confusion? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "<load-on-startup> Confusion?" Watch "<load-on-startup> Confusion?" New topic
Author

<load-on-startup> Confusion?

Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 102

Dear All,

There is an element of web.xml.
<load-on-startup>

What is the purpose of this element.?

I checked many forums but there is something which i couldn't understand.

why is this element always set to 1???
like:
<load-on-startup>1</load-on-startup>

Is this because this is the smallest positive integer?

Please clarify my doubts.

Thanks in advance.

Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
That tag tells the server to create an instance of your servlet when it starts up.

The integer number indicates the load order if there are other servlet you want to be loaded on start up.

The lower is the number, the sooner (among other servlets) the servlet is loaded.

If you don't specify a positive integer value the servlet could be loaded at any time during startup.


Bye,
Nicola
Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 102

Dear Nicola Garofalo,

Thanks for your prompt reply.

But if i don't specify the number , will it make any difference?
If I write 10 instead of 1, what will be the effect?

Thanks in Advance.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

Previously discussed here http://www.coderanch.com/t/465935/Servlets/java/load-startup-value#2089199


[My Blog] [JavaRanch Journal]
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 129
Prash, numbers inside load on startup tag means :- Let suppost that you have 3 servelts and that you want to start at the starting of the server itself. You have one more req. that servlet A should start first, then Servlet B, then servlet C.

This you can do it by using load on startup tag and numeric value inside it.

For example

For Servlet A

<load-on-startup>1</load-on-startup>
For Servlet B:-
<load-on-startup>2</load-on-startup>
For Servlet C:-
<load-on-startup>1</load-on-startup>

In this way you are telling to server that i want to load these servelts in above order.

-Sunil
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

xsunil kumar wrote:that servlet A should start first, then Servlet B, then servlet C.
For Servlet A

<load-on-startup>1</load-on-startup>
For Servlet B:-
<load-on-startup>2</load-on-startup>
For Servlet C:-
<load-on-startup>1</load-on-startup>


the order would be A , C and then B . the value indicates priority
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 129
Less value more priority.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <load-on-startup> Confusion?
 
Similar Threads
reduce the time for converting JSP into servlet
Regarding the init() methods
<load-on-startup> in Deployment Descriptor
Static Initialization Block
servlet start up on server initialization