You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Mark Struberg <st...@yahoo.de> on 2013/03/11 18:58:35 UTC

Re: TomEE undeploy app is not invoking @PreDestroy on CDI @ApplicationScoped bean

Hi mauro!

This is a bit more tricky as it seems you have JMS in the game as well.

Usually there is no difference in the lifecycle of the @Disposes and the @PreDestroy of the disposed instance. Both should get invoked by the container. Disposes is usually only needed if you need to do some destruction work which you cannot do in the bean itself. E.g. if you have a producer for an application managed JPA EntityManager, then you might invoke em.close() in such a @Disposes. Apart from that it's almost the same like @PreDestroy in the bean itself from a user perspective. Of course, the @PreDestroy must be written in the bean you create and not in the producer class.

Btw, your example has an error: you produce a QueueSession but you dispose a QueueConnection ? That would result in a deployment error.

We would need some example in a simple project to reproduce the problem.

LieGrue,
strub




----- Original Message -----
> From: "naciu45@gmail.com" <na...@gmail.com>
> To: struberg@yahoo.de
> Cc: 
> Sent: Monday, March 11, 2013 6:33 PM
> Subject: Re: TomEE undeploy app is not invoking @PreDestroy on CDI @ApplicationScoped bean
> 
> hi from Mauro.
> I have read the tipic on Tomee forum on like the subject of this email. 
> I think that:
> 
> if I move the code of the method annotated @ PreDestroy in the method @Disposes  
> of cdi?????
> 
> for example for create a object @ApplicationScoped with cdi , i use a method 
> @Produces.
> And for destuct it i use the method @Disposes.
> 
> When the application destruct the beans @Applicationscoped , the mehod with the 
> parameter @Disposes it is callled automatically .
> 
> i write a example of a method producer and a method that @Disposes the bean .
> 
> 
> 
> 
> @Produces @Order @ApplicationScoped
>             public QueueSession createOrderSession(@Order QueueConnection conn) 
> throws JMSException {
>                 return conn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
>             }
>         
>             public void closeOrderSession(@Disposes @Order QueueConnection conn) 
> throws JMSException {
>                 conn.close();
>             }
> 
> 
> you think that it is ok ?
> mauro
>