We having multiple MemoryLeaks (found in the catalina.out), while reloading the context.
To clean up these threads, I created an implementation of ServletContextListener.
The contextInitialized()
method is successfully called when a context is created, because I can see the log entries.
But the contextDestroyed()
method is not called so my cleanup code is not invoked. Any ideas why this is happening?
Should I implement another Interface to be noticed when a context needs to be reloaded?
public class MyContextListener implements ServletContextListener {
private static final Logger log = Logger.getLogger(MyContextListener.class);
@Override
public void contextDestroyed(final ServletContextEvent arg0) {
MyContextListener.log.info("destroying Servlet Context");
//Do stuff
MyContextListener.log.info("Servlet Context destroyed");
}
@Override
public void contextInitialized(final ServletContextEvent arg0) {
try {
MyContextListener.log.info("Creating Servlet Context");
//Do stuff
} finally {
MyContextListener.log.info("Servlet Context created");
}
}
}