aspose file tools*
The moose likes Servlets and the fly likes init() called for the first HTTP request, why not earlier? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "init() called for the first HTTP request, why not earlier?" Watch "init() called for the first HTTP request, why not earlier?" New topic
Author

init() called for the first HTTP request, why not earlier?

K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
It seems the init() method from the Servlet interface is called when the first HTTP request is made. This means that the first client always incurs the overhead of all the initialisation. Is it possible to set the servlet container to invoke init() in a web application as soon as the server (Tomcat) is started, rather than it sitting idle waiting for a request and then invoking init()? I can understand it having to compile JSP files (although you can pre-compile them), but I do quite a bit of I/O to setup the environment for the webapp in init() and don't want the first client to have to wait even longer. I would like the application to be 100% ready as soon as its started without having to fire up a browser to make a request, which does the initialisation before its _ready_ for production.
[ May 18, 2005: Message edited by: Kashif Riaz ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Lookup "load-on-startup".
It's an entry in the servlet declaration in your web.xml file.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Ah, thats _exactly_ what I need. Thank you Ben. Do you know where I can find a list of all possible tags which can be used in a web.xml? I might find some hidden gems like this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, the servlet spec.
Link in my signature.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init() called for the first HTTP request, why not earlier?