Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Tomcat and the fly likes execute a servlet  when tomcat starts up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "execute a servlet  when tomcat starts up" Watch "execute a servlet  when tomcat starts up" New topic

execute a servlet when tomcat starts up

Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
Is it possible to execute a servlet when Tomcat starts up?
I'm trying to do some connection pooling with datasource connections.
When Tomcat starts up I want to create a single connection instance and initialize some settings.

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The best thing to do in those cases is use a context listener. Any class that implements javax.servlet.ServletContextListener will have to implement two methods, one of which is contextInitialized. In there, would be the best place to do your setup.

If you still want a servlet, then you can configure the servlet to 'load-on-startup' in web.xml.
I agree. Here's the link:
subject: execute a servlet when tomcat starts up
It's not a secret anymore!