2 Replies Latest reply on Apr 21, 2015 6:53 AM by WarnerJan Veldhuis

    Shutdown order

    WarnerJan Veldhuis Newbie

      Hi all,


      I have an EJB marked as @Singleton @Startup and it has a @PostConstruct and a @PreDestroy method. The @PostConstruct does some initializing, and the @PreDestroy method notifies the connected clients that the server is shutting down. Now, as soon as the @PreDestroy tries to do its job, send a message via JMS, it can't find the ConnectionFactory since that is already undeployed.


      Is there a way to define the order in which several components can be shut down? I have tried to do this with setting Dependencies attribute in the MANIFEST.MF but that didn't make a difference (Unless I have set the wrong dependency ofcourse, org.hornetq and org.jboss.as.messaging?)





        • 1. Re: Shutdown order
          James Livingston Apprentice

          How are you accessing the ConnectionFactory? If you inject it with @Resource, or bind it into the EJB's ENC (java:comp/env) via the deployment descriptor, the container should make sure it is available for the life of the EJB.


          If you look it up from global JNDI in @PostConstruct, then JBoss does not know that you need it available until the end of the @PreDestroy method.

          • 2. Re: Shutdown order
            WarnerJan Veldhuis Newbie

            Well spotted. In @PreDestroy I used a helper class to lookup the ConnectionFactory and the Topic. Instead of that I now created them as @Resource and that informs WildFly properly. I always thought @EJB and @Resource were mainly for convenience, but apparently there is more to it than that