4 Replies Latest reply on Jul 21, 2010 8:15 AM by Prachi M

    timer 4.3 error

    Jas Lam Newbie

      I modified the org.jbpm.examples.eventlistener jUnit test case slightly to introduce a timer as follow with a new <on event="NotifyRCP">

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <process name="EventListener" xmlns="http://jbpm.org/4.2/jpdl">
        <on event="start">
          <event-listener>
            <field name="msg"><string value="start on process definition"/></field>
          </event-listener>
        </on>
        <start g="17,19,48,48">
          <transition to="wait"/>
        </start>
        <state name="wait" g="96,16,104,52">
        <on event="start">
         <event-listener>
              <field name="msg"><string value="start on activity wait"/></field>
         </event-listener>
        </on>
       
          <on event="NotifyRCP">
            <timer duedate="5 seconds"/>
             <event-listener>
                <field name="msg"><string value="NotifyRCP"/></field>       
             </event-listener>      
          </on>      
          <on event="end">
            <event-listener>
              <field name="msg"><string value="end on activity wait"/></field>
            </event-listener>
          </on>
          <transition to="park">
            <event-listener>
              <field name="msg"><string value="take transition"/></field>
            </event-listener>
          </transition>
        </state>
       
        <state name="park" g="231,19,80,52"/>
      </process>
       
      
      
      

       

      In the test case i just add an additional text to the expectedLogs and a sleep

       

      public void testEventListener() {
          ProcessInstance processInstance = executionService.startProcessInstanceByKey("EventListener");
          List<String> expectedLogs = new ArrayList<String>();
          expectedLogs.add("start on process definition");
          expectedLogs.add("start on activity wait");
         
           //START NEW CODE
      
          expectedLogs.add("NotifyRCP");
          try{ Thread.sleep(6000); } catch(Exception e){}
           //END NEW CODE
      
          List<String> logs = (List<String>) executionService.getVariable(processInstance.getId(), "logs");
          
          assertEquals(expectedLogs, logs);
          
          Execution execution = processInstance.findActiveExecutionIn("wait");    
          executionService.signalExecutionById(execution.getId());
          
          logs = (List<String>) executionService.getVariable(processInstance.getId(), "logs");
          expectedLogs.add("end on activity wait");
          expectedLogs.add("take transition");
          
          assertEquals(expectedLogs, logs);
        }
      

       

      When I run this code the first time, it always work!!!! BUT after that I kept failing when the timer triggered!!!  with the following error trace. Could some one confirm this? i tried this on two separate machine and getting the same behavior. Full source code is attached.

       

       

      15:09:12,216 FIN | [ExecuteActivity] execution[EventListener.50007.wait] executes activity(wait)
      [start on process definition, start on activity wait]
      15:09:12,232 FIN | [HibernateSessionResource] ----- committing hibernate tx 23511316 -------------------------------------------------------
      15:09:12,240 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 31798998 --------------------------------------------------------
      15:09:12,241 FIN   | [HibernateSessionResource] ----- committing hibernate tx 32102833 -------------------------------------------------------
      15:09:12,242 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 22677439 --------------------------------------------------------
      15:09:12,251 FIN   | [HibernateSessionResource] ----- committing hibernate tx 32700170 -------------------------------------------------------
      15:09:17,210 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 28678425 --------------------------------------------------------
      ### EXCEPTION ###########################################
      15:09:17,217 SEV   | [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.jbpm.pvm.internal.job.TimerImpl#50012]
           at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1792)
           at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2435)
           at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
           at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
           at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
           at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
           at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
           at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
           at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
           at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:56)
           at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:107)
           at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:64)
           at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
           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.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
           at org.jbpm.pvm.internal.jobexecutor.DispatcherThread.acquireJobs(DispatcherThread.java:126)
           at org.jbpm.pvm.internal.jobexecutor.DispatcherThread.run(DispatcherThread.java:67)
      ### EXCEPTION ###########################################
      15:09:17,219 FIN   | [HibernateSessionResource] ----- rolling back hibernate tx 28848200 -----------------------------------------------------
      15:09:17,270 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 1191324 --------------------------------------------------------
      
      Thank you in advance.
      
        • 1. Re: timer 4.3 error
          HuiSheng Xu Master

          Hi Jas,

            This exception is caused by Optimistic Lock. jBPM used a version column to prevent concurrent conflict. So maybe there are more than one thread were processing the Timer. After the first one update the timer, the other will get the StaleObjectStateException.

           

            But I can't reproduce this Exception. I use jBPM-4.3 and hsqldb. The project is in the attach.

          • 2. Re: timer 4.3 error
            Prachi M Newbie

            Hi Jas,

             

            I get the same error on timer invocation.

            Could you please tell me if you got rid of the same? And how did you proceed?

             

            I am using a custom node as async and if an activity on that node throws an exception, it goes to a wait state, where it waits for 10 minutes and goes to the custom node again for retrying that activitiy.

            The retry counter has been set to 3. But on first loop invocation, i.e. the first time when timer is invoked, it throws a stale state exception, and constraint violation exception.

             

            Please help me. Its very urgent. I am badly stuck and not able to move ahead.

             

            Many thanks,

            Prachi

            • 3. Re: timer 4.3 error
              Maciej Swiderski Master

              Please give a try with latest 4.4 version. The problems you mentioned should be already solved.

               

              Some times stale state exception can be printed out but invocation is done properly, thanks to retry mechanism that is built in jBPM.

              • 4. Re: timer 4.3 error
                Prachi M Newbie

                Thanks for the response Maciej. It did work with jBPM 4.3 as well, but the response in quite sporadic. At times, it runs perfectly, and at other times it throws the above mentioned errors. It goes into an inactive-scope for state and does nothing beyond that.

                 

                Anyway, I tried it with jBPM 4.4, and it seems to work now. But our project technology landscape includes jBPM 4.3 as of now, so was looking for a solution in the same version.

                Thanks anyway.

                 

                Rgds,

                Prachi