Catalina has a shutdown hook which I have never happened to use but
you should be able to find it on the net. Google is our friend, right?
The other way is to use the
ServletContextListener.contextDestroyed(...) method. I like this one
more. Not I don't like Catalina but you don't want to depent on a
specific server.