2 Replies Latest reply on Apr 20, 2010 8:35 AM by jelies

    Trouble with jBPM 4 job executor and context reloading.

    unsavory

      In my development environment I have resorted to disabling the jBPM 4.3 job executor because when I publish any changes to my jBoss server which results in a context reload, the job executor thread doesn't die off.  The old thread continues to run and I get the following exception:

       

      14:36:44,981 SEVERE [org.jbpm.pvm.internal.jobexecutor.DispatcherThread] exception in job executor thread. waiting 5000 milliseconds: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
          at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:171)
          at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1101)
          at org.jbpm.pvm.internal.env.SpringContext.get(SpringContext.java:59)
          at org.jbpm.pvm.internal.env.BasicEnvironment.get(BasicEnvironment.java:139)
          at org.jbpm.pvm.internal.env.BasicEnvironment.get(BasicEnvironment.java:130)
          at org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:201)
          at org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:190)
          at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.resolveTransactionManager(SpringTransactionInterceptor.java:89)
          at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:52)
          at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
          at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
          at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
          at org.jbpm.pvm.internal.jobexecutor.DispatcherThread.acquireJobs(DispatcherThread.java:126)
          at org.jbpm.pvm.internal.jobexecutor.DispatcherThread.run(DispatcherThread.java:67)

       

      Does anyone have any ideas how to get around this?  I am using the jBoss server adapter within eclipse.

        • 1. Re: Trouble with jBPM 4 job executor and context reloading.
          unsavory

          In case this helps someone else, I found a solution to this problem.  By creating a Spring ApplicationListener that listens to the shutdown event, you can signal the jBPM job executor to shut down when the context is stopped.

           

          /**
          * A Spring ApplicationListener that will properly shut down
          * the jBPM process engine when the Spring context is destroyed.
          *
          * @author Caine
          * Created: Mar 5, 2010 - 4:30:58 PM
          */
          @Component
          @SuppressWarnings("unchecked")
          public class SpringJbpmJobExecutorShutdownHook implements ApplicationListener {
             
              //~~ Static Fields/Initializers ==========================
             
              static final Logger log = Logger.getLogger(SpringJbpmJobExecutorShutdownHook.class);
             
              //~~ Dependencies ========================================
             
              @Resource
              ProcessEngine processEngine;
             
              //~~ Methods =============================================
             
              public void onApplicationEvent(ApplicationEvent event) {
                  if (event instanceof ContextClosedEvent ) {
                      log.info("Spring ApplicationContext shutting down.  Closing jBPM process engine.");
                      processEngine.close();
                      log.info("jBPM process engine closed.");
                  }
              }
          }

           

          More details about the problem, and why it matters can be found on my blog post here:  http://captaincaveman.posterous.com/how-to-shut-down-the-jbpm-43-job-executor-wit

          • 2. Re: Trouble with jBPM 4 job executor and context reloading.
            jelies

            great solution, thanks for the link!