• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lookup "load-on-startup".
It's an entry in the servlet declaration in your web.xml file.
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the servlet spec.
Link in my signature.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic