0 Replies Latest reply on Sep 8, 2014 2:22 PM by Kornelius Prell

    Shutdown Hook for Wildfly to gracefully stop batch jobs

    Kornelius Prell Newbie

      Hi Wildfly community,


      in the last days I've tried to find a way for my web application to get notified when Wildfly is going to shutdown.

      The application utilizes the Batch API and on shutdown I'd like to check if any jobs are running, stop them and log some information.

      Therefore I need to access the JobOperator, typically via




      I've tried the different approaches presented in this article:



      1. Register Shutdown Hook with Runtime.getRuntime().addShutdownHook()

      2. Use @PreDestroy on a EJB

      3. Additionally I've used the contextDestroyed method of a @WebListener annotated class (ServletContextListener)


      None of those approaches fit my requirement, as it isn't possible to instantiate/inject any objects at the time the application gets notified about the shutdown.

      An access of BatchRuntime.getJobOperator always results in something alike:


      java.lang.IllegalStateException: JBAS020562: The batch environment was not configured or has been removed.


      Is there an event or hook that can be used so that the application gets notified before new injections aren't possible anymore?


      Thanks for your help!