permaculture playing cards*
The moose likes Servlets and the fly likes load-on-startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "load-on-startup" Watch "load-on-startup" New topic
Author

load-on-startup

devayani Devasthali
Ranch Hand

Joined: Aug 25, 2005
Posts: 40
hello,
pls help me in understanding servlet basics---
1)if two servlets has the same value for load-on-startup what happens?
2)if I give negative value for load-on-startup , what does it mean?
thanx in advance
regards
devayani
Lalitha Gottumukkula
Ranch Hand

Joined: May 24, 2005
Posts: 45
<load-on-startup> : WebLogic Server initializes this servlet when WebLogic Server starts up. The content of this element must be a positive integer indicating the order in which the servlet should be loaded. Lower integers are loaded before higher integers. If no value is specified, or if the value specified is not a positive integer, WebLogic Server can load the servlet in any order in the startup sequence.


I think, if two servlets have the same value for <load-on-startup> then any of the servlet can be loaded first.

And for the second question, I think you can get from the above quote....

Thanks,
Lalitha.
devayani Devasthali
Ranch Hand

Joined: Aug 25, 2005
Posts: 40
first of all thanx for the reply,
actually i am using tomcat 5
when I tried the value "-1" for load-on-startup, it doesnt get loaded with server loading.
when I called that servlet , then its loaded.. so I got confused? could u pls explain this to me?

Also would like to know- cant we specify load-on-startup for every servlet?anyway I have written servlets means I am going to call them in my application. So to save time for instanciation and loading of servlet after it is requested can we do that at the time of loading of server itself?

thanx in advance
regards
Devayani
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello Devayani,
Definitely you can specify <load-on-startup> for each servlet but you will write it for the servlets which you need to initialize at server startup.
e.g. If you use <load-on-startup> for each servlet then, if server supports instance pooling (which most web servers use ,i suppose) lot many instances will be created in a server memory even if you are not using them...i hope this is clear... so writing <load-on-startup> for each servlet is not a very good idea normally (Although practically this is possible)
You will definitely use this for a Servlet like ActionServlet in Struts Framework (if you are not aware of the Struts then just go through some basic part of it)since its a main controller in Struts Framework & needs to be initialized before any request hits the server

Shrinivas
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Shrinivas Mujumdar:

If you use <load-on-startup> for each servlet then, if server supports instance pooling (which most web servers use ,i suppose) lot many instances will be created in a server memory even if you are not using them...


Not entirely true..
Unless your servlets implement SingleThreadedModel, they won't be pooled (there will only be on instance of each servlet per container).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This is from the servlet spec:



In other words the behaviour will be container specific and not guaranteed to work the same way across different versions of any particular container.

In light of this, there is no good reason to use negative numbers for this value.
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Just curious, why do we ever want to put in a negative number?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Alec Lee:
Just curious, why do we ever want to put in a negative number?


If I had to guess, I would say to put a new servlet at the top of the list without having to reorder all of the others.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Not entirely true..
Unless your servlets implement SingleThreadedModel, they won't be pooled (there will only be on instance of each servlet per container).

ya I do agree.....but
SingleThreadModel interface is Deprecated Ben..in servlet 2.4 Spec. so why to talk about the stuff which is not recommended.......


Shrinivas
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Shrinivas Mujumdar:

ya I do agree.....but
SingleThreadModel interface is Deprecated Ben..in servlet 2.4 Spec. so why to talk about the stuff which is not recommended.......

Shrinivas


First, I was not recommending it.
Second, since most of a developer's time is spent maintaining existing code it is important that we understand all of the API for the tools we are using; including the deprecated aspects of it.

My main point is that pooling is a non-issue except for SingleThreadedModel.
Using load-on-startup will not cause more instances of a given servlet to exist than not using it (unless of course nobody ever hits it, in which case it would never be loaded at all without load-on-startup).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: load-on-startup
 
Similar Threads
sinificance of value of tag <load-on-startup> in web.xml
Loading two servlets at the startup?
What does load-on-startup?
Question on load-on-startup
Websphere unable to parse Web.xml