This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Tomcat and the fly likes How to run a program on application startup in tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to run a program on application startup in tomcat?" Watch "How to run a program on application startup in tomcat?" New topic
Author

How to run a program on application startup in tomcat?

utsav gupta
Ranch Hand

Joined: Mar 19, 2009
Posts: 57
Hi All

My requirement is to run a java program as soon as my web app loads on the tomcat server. What is the best way to do it?

I was thinking of calling the method inside the init() method of the servlet, but if i am correct that might run the program during the application startup or might run it when the first request hits. So how do ensure that the method is called when the application is loaded on the server.

You may also recommend me a better way of doing so.

Thanks!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17161
    
  27

Once upon a time, it was, in fact common practice to use an init() method for that purpose. You simply marked the servlet as "load on startup".

However, these days, the recommended procedure is to use a ContextListener to invoke your run-on-startup code.


An IDE is no substitute for an Intelligent Developer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run a program on application startup in tomcat?
 
jQuery in Action, 3rd edition