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
<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....
Joined: Aug 25, 2005
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?
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
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).
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.......
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).