[weld-dev] Do we need a Context.destroy() ?

Mark Struberg struberg at yahoo.de
Tue Jan 12 09:48:09 EST 2010


Hi!

I'm currently writing a CDI extension and like to do the 'cleanup' properly.

So, what does happen if a WebApp gets stopped?
One thing is sure: a Context implementation must destroy all contextual instances it still holds (to make sure that e.g @PreDestroy gets called, etc). 

But how to do this properly?

My first idea was to use 

public void destroy( @Observes BeforeShutdown beforeShutdown)
{
  for(allContextualInstances)
    contextual.destroy(..)
}

but there is a timing issue with this approach. It is not defined which bean receives the BeforeShutdown event first. Thus if my extension is the first which gets this event and destroys all contextual beans it maintains, then all following beans listening to BeforeShutdown and still referencing some beans with my special context will simply crash.

Do you have an idea what we can do to work around this problem?

If not, I'd prefer to introduce a new destroy() method in the Context interface which gets called by the container after all BeforeShutdown events got fired.

txs and LieGrue,
strub 





      


More information about the weld-dev mailing list