J2EE stop detection

Is there a way for a function to be called if/when my application is stopped, e.g. tomcat restarts. I’m having an issue where threads are not being properly stopped when the application is stopped.

The close() function in Application is not getting called.




maybe ServletContextListener helps you:

public class MyServletContextListener implements ServletContextListener {

  public void contextDestroyed(ServletContextEvent arg0) {

  public void contextInitialized(ServletContextEvent arg0) {



That did it. Thank you.