0 Replies Latest reply on Feb 15, 2013 10:28 AM by vercruysse_tim

    Concurrency problem with persistent JBPM + Drools

    vercruysse_tim

      Hi all,

       

      We have a problem that when multiple threads try to fetch process variables an exception is thrown:

      java.lang.NullPointerException
                     org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:67)
                     org.jbpm.persistence.processinstance.ProcessInstanceInfo.update(ProcessInstanceInfo.java:189)
      

       

      the code in our EJB is:

      public Object getProcessVar(long processInstanceId, String varName) {
           try{
                WorkflowProcessInstance p = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId);
                var = p.getVariable(varName);
           } catch(Throwable x) {x.printStackTrace()}
      return var;
      }
      

       

      This exception is thrown when we do multiple calls (around 40) from our Spring context to this EJB method.

       

      We found that most of the time that when we do a context switch from Spring to EJB  drools automatically tries to update a ProcessInstanceInfo entity with procesInstanceInfo.update() or invokes jPAProcessInstanceManager.clearProcessInstances() to disconnect all the processInstances. It happens now that drools tries to update a processInstanceInfo that points to a processInstance that previously has been disconnected, hence the error.

       

      My guess is that the multiple threads mess up the order of the transactions so that some processInstanceInfo entities are in invalid states.

       

      Does anyone know how to solve this issue?

       

      We use JBPM 5.2, Spring 3 and Hibernate 4.

      KnowledgeSession: statefullKnowledgeSession, with a commandBasedWSHumanTaskHandler.

      Persistence transactions: JTA and JBossTransactionManagerLookup

       

      Thanks!