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

    Shutdown order

    nlsurfman

      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?)

       

      Cheers!

       

      WarnerJan

        • 1. Re: Shutdown order
          jameslivingston

          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
            nlsurfman

            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


            Thanks!