How can I know when my tomcat web app is suspended?

I want to receive an "event" before tomcat stops my web application.
My application has to "complete" stuff before it closes.

+1


source to share


3 answers


I think I found, I created a servlet and implemented

public void destroy();

      



I have verified that this method is called when I stop the application from the tomcat admin page and even when I close the tomcat server

JavaEE 6 doc on servlets

+2


source


A servlet that doesn't respond to anything destroy()

is functional, but a bit hacky. Servlets are designed to handle web requests.

The right thing to do is to implement ServletContextListener and make your wrapper in the method contextDestroyed()

.



Register ServletContextListener

yours in web.xml, for example:

<listener>
    <listener-class>com.foo.MyListener</listener-class>
</listener>

      

+4


source


You can write a ContextListener that responds to unfolding / unfolding events. Perhaps you can send an email when the context is not expanded.

I'm just not sure if this event is fired if the app server is stopped.

+1


source







All Articles