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

Mark Struberg struberg at yahoo.de
Tue Jan 12 10:50:58 EST 2010


to further clarify what I mean:

section 11.5.4 BeforeShutdown event:
"The container must fire a final event _after_ it has finished processing requests and destroyed _all_ contexts."

Obviously this isn't working for Contexts defined as portable extensions, is it? This may state 'built-in contexts'.

txs and LieGrue,
strub

--- On Tue, 1/12/10, Mark Struberg <struberg at yahoo.de> wrote:

> From: Mark Struberg <struberg at yahoo.de>
> Subject: Do we need a Context.destroy() ?
> To: "Gavin King" <gavin.king at gmail.com>
> Cc: "Java Community Process JSR #299 Expert List" <JSR-299-EG at jcp.org>, "Weld-Dev" <weld-dev at lists.jboss.org>
> Date: Tuesday, January 12, 2010, 3:48 PM
> 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