6 Replies Latest reply on Nov 3, 2009 3:54 AM by Joram Barrez

    Timer throwing exception intermittently

    Sridhar Alapati Newbie

      I'm getting the following error at times when my timers are firing.
      11:19:51,157 ERROR [ExecuteJobCmd] exception while executing 'timer[46|2009-10-28 11:19:51,040|timeout]'
      org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.jbpm.pvm.internal.model.ExecutionImpl#152]
      at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:409)
      at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:108)
      at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:97)
      at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
      at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
      at org.jbpm.pvm.internal.model.ExecutionImpl_$$_javassist_4.getActivity(ExecutionImpl_$$_javassist_4.java)
      at org.jbpm.pvm.internal.job.TimerImpl.execute(TimerImpl.java:94)
      at org.jbpm.pvm.internal.job.TimerImpl.execute(TimerImpl.java:52)
      at org.jbpm.pvm.internal.cmd.ExecuteJobCmd.execute(ExecuteJobCmd.java:76)
      at org.jbpm.pvm.internal.cmd.ExecuteJobCmd.execute(ExecuteJobCmd.java:42)
      at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
      at org.jbpm.pvm.internal.tx.jta.JtaTransactionInterceptor.executeInNewTx(JtaTransactionInterceptor.java:79)
      at org.jbpm.pvm.internal.tx.jta.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:61)
      at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
      at org.jbpm.pvm.internal.tx.jta.JtaRetryInterceptor.executeWithRetry(JtaRetryInterceptor.java:52)
      at org.jbpm.pvm.internal.tx.jta.JtaRetryInterceptor.execute(JtaRetryInterceptor.java:45)
      at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:46)
      at org.jbpm.pvm.internal.jobexecutor.JobParcel.run(JobParcel.java:48)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)

      Sample timer in my process definition:

       <state g="138,450,127,52" name="Validate">
       <on event="timeout">
       <timer name="checkValidity" duedate="3 minutes" repeat="2 minutes"/>
       <event-listener class="some.class.CheckValidityEvent">
       <field name="idType"><string value="ID"/></field>
       <transition g="-72,-22" name="valid" to="complete"/>
       <transition g="-72,-22" name="invalid" to="end"/>

      The timers tend to exist though and run just fine on the next timeout.
      I'm using jbpm 4.1 on jboss 5.1. Thanks in advance.

        • 1. Re: Timer throwing exception intermittently
          Joram Barrez Master

          Could you provide a basic test case for this so we can test it against trunk?

          • 2. Re: Timer throwing exception intermittently
            Sridhar Alapati Newbie

            Sure. Thanks for the response. You could use the below process defnintion and EventListener class to try to reproduce this:

            <?xml version="1.0" encoding="UTF-8"?>
            <process name="MyWorkflow" xmlns="http://jbpm.org/4.0/jpdl">
             <start g="11,265,80,40">
             <transition to="fork"/>
             <fork g="76,263,80,40" name="fork">
             <transition to="ValidateOne"/>
             <transition to="ValidateTwo"/>
             <state g="138,450,127,52" name="ValidateOne">
             <on event="timeout">
             <timer name="checkValidityForOne" duedate="3 minutes" repeat="2 minutes"/>
             <event-listener class="some.class.CheckValidityOneEvent">
             <field name="idType"><string value="ID_ONE"/></field>
             <transition g="-72,-22" name="valid" to="complete"/>
             <transition g="-72,-22" name="invalid" to="end"/>
             <state g="138,450,127,52" name="ValidateTwo">
             <on event="timeout">
             <timer name="checkValidityForTwo" duedate="4 minutes" repeat="5 minutes"/>
             <event-listener class="some.class.CheckValidityTwoEvent">
             <field name="idType"><string value="ID_TWO"/></field>
             <transition g="-72,-22" name="valid" to="complete"/>
             <transition g="-72,-22" name="invalid" to="end"/>
             <join g="706,212,48,48" multiplicity="2" name="complete">
             <transition to="end"/>
             <end g="779,213,48,48" name="end"/>

            It just has a fork, two concurrent activities (events), and a join.

            My sample event listener class:
            public class CheckValidityOneEvent implements EventListener {
             private final Logger log = Logger.getLogger(this.getClass());
             public void notify(EventListenerExecution execution) throws Exception {
             try {
             // business logic, check for condition
             // if condition met, signal execution by id
             executionService.signalExecutionById(execution.getId(), "valid");
             // otherwise, do nothing
             } catch (Exception ex) {
             // catch all exceptions and don't rethrow them.
             log.error("Exception occured: " + ex.getMessage());

            So on each timeout, the timer will perform a check and transitions to valid only if the check is successful. Otherwise it does nothing. I won't throw any exceptions up the chain.
            I have my .bar and library jar deployed to jboss 5.1 GA. Let me know if you need anymore information.

            • 3. Re: Timer throwing exception intermittently
              Ronald van Kuijk Master

              Could this by accident be related to the cases with two tasks in forks? Might be different symptoms of the same issue.

              @Sridhar: If you could make a testcase like in http://www.jboss.org/index.html?module=bb&op=viewtopic&t=158424 that would save Joram some time.

              • 4. Re: Timer throwing exception intermittently
                Sridhar Alapati Newbie

                I'm not following when you say two tasks in fork. Could you elaborate a bit more on it? Thanks.

                • 5. Re: Timer throwing exception intermittently
                  Sridhar Alapati Newbie

                  I found the reason for this behavior.

                  I have repeat timers in my process definition. The timeout event listeners for those timers check for a particular condition and if it is met, transition to a new activity. What's happening in that case is for some reason, though the timer is getting deleted from the database, the timer id is still being used by DispatcherThread class. It passes along this id to the ExecuteJobCmd which throws the exception I posted above as it can't find any timer in the database by that id. It retries upto 3 times and then gives up. That's why I see the exception throws 3 times in the logs.

                  So is there a better way we could turn off the repeat timers when transitioning to a new activity?

                  • 6. Re: Timer throwing exception intermittently
                    Joram Barrez Master

                    If the functionality is as you describe, then it is a bug. Can you debug the code and find out why exactly the id is still in the DispatcherThread (coincidence?)