Can someone say how I might implement a function that gets called when jetty 9 has shutdown. I cannot use the context destroy function because this gets called if the webapps are being refreshed. I need a function that gets called just before jetty shuts down completely. I cannot use a lower level shutdown hook? http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread) because these shutdown hooks execute before the webapp contexts are destroyed and I need to have all the contexts destroyed before my functions runs. Also In the case where jetty is refreshing a context I don't want my code to execute. I only want it to run when jetty is about to terminate and all the contexts are destroyed.