cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping Job Executor

arkadi
Champ in-the-making
Champ in-the-making
Is there a way to stop Job Executor <property name="jobExecutorActivate" value="true" /> nicely at webapp context shutdown? We have a listener:
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
       if (processEngine != null)
            ProcessEngines.destroy();
    }
but then later:
2011.1.9 22:19:31 org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load org.apache.ibatis.exceptions.ExceptionFactory.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1562)
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:77)
   at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:191)
   at org.activiti.engine.impl.persistence.entity.JobManager.findNextJobsToExecute(JobManager.java:97)
   at org.activiti.engine.impl.cmd.AcquireJobsCmd.execute(AcquireJobsCmd.java:49)
   at org.activiti.engine.impl.cmd.AcquireJobsCmd.execute(AcquireJobsCmd.java:32)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.jobexecutor.JobAcquisitionThread.run(JobAcquisitionThread.java:63)
2011.1.9 22:19:31 org.apache.catalina.loader.WebappClassLoader findResourceInternal
INFO: Illegal access: this web application instance has been stopped already.  Could not load org/apache/ibatis/exceptions/ExceptionFactory.class.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
Exception in thread "JobAcquisitionThread" java.lang.NoClassDefFoundError: org/apache/ibatis/exceptions/ExceptionFactory
   at org.apache.ibatis.session.defaults.DefaultSqlSession.close(DefaultSqlSession.java:169)
   at org.activiti.engine.impl.db.DbSqlSession.close(DbSqlSession.java:450)
   at org.activiti.engine.impl.interceptor.CommandContext.closeSessions(CommandContext.java:154)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:126)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.jobexecutor.JobAcquisitionThread.run(JobAcquisitionThread.java:63)
And I believe the JobAcquisitionThread must be also setup as daemon thread, but currently it is not.
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
The job-aquisition-thread will be shutdown gracefully when the shutdown is called, this is done by the ProcessEngines.destroy().

/**
   * Triggers a shutdown
   */
  public void shutdown() {
    if (isActive) {
      log.info(getName() + " is shutting down");
      isActive = false;
      interrupt();
      try {
        join();
      } catch (InterruptedException e) {
        log.log(Level.WARNING, "Interruption while shutting down " + this.getClass().getName(), e);
      }
    }
  }

The current (calling) thread will wait for it to exit clean, could be that job-executor is still running a process, so deamon-thread is not an option. You should call the destroy BEFORE the webapp is actually shut down…