users@jersey.java.net

Missing shutdown hook at end of resources lifecycle.

From: Kristof <kr_adr_at_yahoo.co.uk>
Date: Sun, 17 Oct 2010 10:27:01 +0100 (BST)

Hi all,
I want to use Jersey to build a REST service around an api that accesses a database. The api has initialize and shutdown methods to setup/shutdown connection pool, database connections etc.
The main issue I have is that I don't know of a way to call the shutdown method when the jersey resource lifecycle ends. For example when a user shuts down/undeploys/reloads the webapp in a Tomcat environment.  Jersey does not seem to provide any hooks to accomplish this?  There are pre- and post request hooks but no hooks that are called at startup/shutdown of the application/container.
Shutting down properly is required to avoid memory leaks. 
To me this looks like something trivial but none of the REST frameworks that I looked at (Jersey, Resteasy, Restlet) seem to support this? There was a similar post on the mailing list asking the same question: https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=4271 but the questions was not really answered.
Ideally the init/shutdown should also be integrated with Guice/Spring support so init/shutdown methods can be invoked on Guice/Spring injected objects.
Any suggestions?
Thanks!Kristof