Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execute a servlet when tomcat starts up

 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
Dave
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic