Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

load-on-startup with 0 value

 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a servlet and the entry in the web.xml is as follows

<servlet>
<servlet-name>WebGraph</servlet-name>
<display-name>WebGraph</display-name>
<servlet-class>a.b.c.Graph</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

Also there is no init method specified in the above servlet.

Please let me know if the same servlet will be initialised during server start up?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the value is 0 or greater, it indicates an order for servlets to be loaded, servlets with higher numbers get loaded after servlets with lower numbers.

some containers like tomcat don't process entries with a value less than 0.
 
Vamsi Mohan
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you give the value as "0" as load-on-startup, the servlet automatically started/initiated while startup without any user call. This is called "Dynamic Loading". If you give "1", the user has to call the servlet explicitly. This is called "Lazy Loading".
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamsi Mohan wrote:If you give the value as "0" as load-on-startup, the servlet automatically started/initiated while startup without any user call. This is called "Dynamic Loading". If you give "1", the user has to call the servlet explicitly. This is called "Lazy Loading".

Completely incorrect. Any non-negative value for load-on-startup will cause the servlet to load on startup. A negative value leaves it up to the container.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Abhishek,

I am pasting few line from hfsj page# 628, I believe, this would clear all your doubts. Regarding load-on-startup option.

If you want servlets to be loaded at deploy time (or at server restart time) rather than on first request, use the <load-on-startup> element in the DD. Any non-negative value for <load-on-startup> tells the Container to initialize the servlet when the app is deployed (or any time the server restarts).

If you have multiple servlets that you want preloaded, and you want to control the order in which they’re initialized, the value of <load-on-startup> determines the order! In other words, any non-negative value means load early, but the order in which servlets are loaded is based on the value of the different <load-on-startup> elements.

<load-on-startup>4</load-on-startup> does NOT mean “load four instances of the servlet”. It means that this servlet should be loaded only AFTER servlets with a <load-on-startup> number less than four are loaded. And what if there’s more than one servlet with a <load-on-startup> of 4? The Container loads servlets with the same value in the order in which the servlets are declared in the DD.
 
Praveen Kumar Gupta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi All
<load-on-startup>-1</load-on-startup>
negative value shows that servlet object will be instantiate when the first request comes.

<load-on-startup>x</load-on-startup>
x = 0,1,2,3 and so on...

define that servlet object will be instantiate when the server starts.

and the x value difine the priority of the servet which instantiate first respectively



 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
x value difine the priority of the servet which instantiate first respectively


it should be that +ive x value define the reverse order of priority. That means higher the value= lower the priority.
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Rath wrote:Hi

I have a servlet and the entry in the web.xml is as follows

<servlet>
<servlet-name>WebGraph</servlet-name>
<display-name>WebGraph</display-name>
<servlet-class>a.b.c.Graph</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

Also there is no init method specified in the above servlet.

Please let me know if the same servlet will be initialised during server start up?


Abhishek,

To answer your question yes the servlet will be loaded and it doesn't matter whether the init method is implemented or not and if it is implemented it is guaranteed to be called before servlet handles any request.

hope this helps.

Thanks,
Rahul
 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the details.
 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Vamsi Mohan wrote:If you give the value as "0" as load-on-startup, the servlet automatically started/initiated while startup without any user call. This is called "Dynamic Loading". If you give "1", the user has to call the servlet explicitly. This is called "Lazy Loading".

Completely incorrect. Any non-negative value for load-on-startup will cause the servlet to load on startup. A negative value leaves it up to the container.


it depends on container also.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pooja jain wrote:
Bear Bibeault wrote:
Vamsi Mohan wrote:If you give the value as "0" as load-on-startup, the servlet automatically started/initiated while startup without any user call. This is called "Dynamic Loading". If you give "1", the user has to call the servlet explicitly. This is called "Lazy Loading".

Completely incorrect. Any non-negative value for load-on-startup will cause the servlet to load on startup. A negative value leaves it up to the container.


it depends on container also.


As Bear said, for negative numbers it's up to the container to decide. But it does *not* depend on containers to decide, what load order they follow for positive numbers. The order is mandated by the spec (which by the way is really very clear about the load-on-startup):

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.

 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jaikiran & bear.
 
goyankavicky gupta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks n & bear.
 
G krishna kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for load-on-startup tag in web.xml it is always recomanded to have a positive number or zero.
load-on-startup : it defines when the object has to created based on the priority of a given number.
here zero has the highest priority.
if two servlet are having the same priority then it deffer from server to server when the object will be created for the respective servlet.
for example :
in tomcat... it chooses based on the alphabetical order.
in case of web logic the server which is configured first will be given the first priority.
in case of negative number the server will discard the the tag load on startup.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic