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.

Thanks.

-Rich

Hi,

maybe ServletContextListener helps you:

public class MyServletContextListener implements ServletContextListener {

  @Override
  public void contextDestroyed(ServletContextEvent arg0) {
    
  }

  @Override
  public void contextInitialized(ServletContextEvent arg0) {
    
  }
}

web.xml:

<listener>
   <listener-class>org.example.MyServletContextListener</listener-class>
</listener>

That did it. Thank you.