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:48:54 +0100

On Tue, Jul 8, 2008 at 12:04 AM, <glassfish_at_javadesktop.org> wrote:
> Are you suggesting, Stephen, that if I have a SessionBean web service deployed, that I still need minimal WAR in order to get the WebService lifecycle methods called on SessionBeans web services?

In effect, yes. If you read the specification, as far as I recall the
@PostDestroy method is called only if:

* the session bean is about to be finalized; _and_
* your application is still deployed

So if your application is undeployed and then the garbage collector
runs... @PostDestroy does not make any sense as your application has
been undeployed.

Think of @PostDestroy as being for when your bean gets created as part
of a pool, and the pool grows temporarily bigger than its resting size
to accommodate a surge in requests. The container says, ohh I've got
too many of these around, let's get rid of some of them... In those
cases will the lifecycle method be called.

You are trying to see the lifecycle method get called when it makes no
sense (to the container) as anything that it could call has been
unhooked from the container (because your context is undeployed,
either by being undeployed or being stopped)

I know it's ugly, but if you want to be standards compliant and not
tie yourself to glassfish, the WAR with ServletContextListener is the
only way to do it :-(

-Stephen