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

Gavin King gavin.king at gmail.com
Wed Jan 13 01:42:00 EST 2010


Spec section 11.5 titled "Container Lifecycle Events":

"Observer methods of these events must belong to extensions."

A bean can't observe BeforeShutdown.

On Tue, Jan 12, 2010 at 8:48 AM, Mark Struberg <struberg at yahoo.de> wrote:
> 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
>
>
>
>
>
>
>



-- 
Gavin King
gavin.king at gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org



More information about the weld-dev mailing list