users@glassfish.java.net

Re: _at_PreDestroy method in web service not called when web app undeployed?

From: Stephen Connolly <stephen.alan.connolly_at_gmail.com>
Date: Tue, 8 Jul 2008 08:52:55 +0100

On Fri, Jul 4, 2008 at 5:23 PM, <glassfish_at_javadesktop.org> wrote:
> I have a web service that needs to do some cleanup (shut down a background thread). So I implemented a method annotated with @PreDestroy. Unfortunately, the method is never called. I would have expected it to be called when the web service application is undeployed or disabled, but it is not.

The other thing I notice is that you are starting a background
thread.... AFAIK you should not really be starting threads in a
container.... (yes, I know everyone, myself included, does it)

If I remember correctly, background threads are supposed to be started
within a JCA resource adapter as it is the only thing that is given a
WorkManager by the container.

Man I hope they fix this for JavaEE 6.... I don't see why WorkManagers
are restricted to JCA adapters... and the fact that it is a separate
instance and not an ExecutorService... sure that's just wrong!