cancel
Showing results for 
Search instead for 
Did you mean: 

JobExecutor Stops in Clustered Enviorment

er3n
Champ in-the-making
Champ in-the-making
Hi
  We are using activiti engine in our project in clustered enviorment. We are getting an error like.


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.containsBean(AbstractApplicationContext.java:1091)
   at org.activiti.engine.impl.cfg.SpringBeanFactoryProxyMap.containsKey(SpringBeanFactoryProxyMap.java:46)
   at org.activiti.engine.impl.scripting.BeansResolverFactory.containsKey(BeansResolverFactory.java:30)
   at org.activiti.engine.impl.scripting.ScriptBindings.containsKey(ScriptBindings.java:52)
   at javax.script.SimpleScriptContext.getAttributesScope(SimpleScriptContext.java:265)
   at com.sun.script.javascript.ExternalScriptable.put(ExternalScriptable.java:159)
   at com.sun.script.javascript.RhinoScriptEngine.getRuntimeScope(RhinoScriptEngine.java:285)
   at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:145)
   at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:167)
   at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:216)
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:75)
   at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:43)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:76)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:500)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:492)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:76)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:500)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:492)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:76)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:500)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:492)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:50)

We are starting JobExeturors in a thread manualy with the method above.

@Override
   public void run() {
      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
      if(((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().isActive()==false){
         
         try {
            Thread.sleep(300000);
         } catch (InterruptedException e) {
            logger.fatal("JobExecutor aktiflestirme sirasinda interrupt geldi. JobExecutor aktiflestirilemedi!!!");
            return;
         }
         ((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().start();
         logger.info("JobExecutor aktiflestirme basarili.");
         

      } else {
         logger.info("JobExecutor zaten aktif.");
      }

When i get this error, without stoping application, i am calling ;
   
  ( (ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().isActive()
and it return false but when job duedate reached jobexecuter triggers jobs.

To sum up my problem is proccess engine looses referance to JobExecutor and when jobExecutor triggers i get (BeanFactory not initialized or already closed ) error. I am manualy start proccess engine again at the runtime problem is solved but after a little time latter job executor getting the same error again and
   
  ( (ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().isActive()

returns false.

Also my spring configuration is:

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="databaseType" value="oracle" />
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="hibernateTransactionManager" />
      <property name="databaseSchemaUpdate" value="false" />
      <property name="history" value="audit" />
      <property name="jobExecutorActivate" value="false" />
      <property name="jobExecutor" ref="jobExecutor"/>
      <property name="idBlockSize" value="${activiti.processEngineConfiguration.idBlockSize}"/>
   </bean>

   <bean id="jobExecutor" class="org.activiti.engine.impl.jobexecutor.JobExecutor">
      <property name="corePoolSize" value="${activiti.jobExecutor.corePoolSize}"/>
      <property name="lockTimeInMillis" value="${activiti.jobExecutor.lockTimeInMillis}"/>
      <property name="maxJobsPerAcquisition" value="${activiti.jobExecutor.maxJobsPerAcquisition}"/>
      <property name="maxPoolSize" value="${activiti.jobExecutor.maxPoolSize}"/>
      <property name="queueSize" value="${activiti.jobExecutor.queueSize}"/>
      <property name="waitTimeInMillis" value="${activiti.jobExecutor.waitTimeInMillis}"/>
   </bean>

Do u have any idea about this problem?

Kind regards…
Eren Öztürk
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
Spring-context is only active when you actually use spring. If you use the "ProcessEngines.getDefaultProcessEngine();" this will actually just read your config, pull out the process-engine bean and afterwards close the configuration-context.

If you want to keep using spring-context, you should obtain the process-engine from the spring-context YOU build and maintain, as you usually would bootstrap application-context