7 Replies Latest reply on Apr 10, 2013 2:05 AM by swiderski.maciej

    Not terminating process if timer

    atran

      Hi,

       

      I am using Eclipse and jBPM 5.4.0 workflow engine. Whenever I use a timer as simple as below (FigB), and I launch it in Eclipse, the Terminate End Event doesn't end the Java process (FigA). However, if I delete the timer, the process ends. It seems this is a bug? Has anyone encountered the same issue? Thank you.

       

      Antoine

       

      FigA: The process doesn't end

      SimpleTimer.png

       

      FigB: Simple Timer:

      SimpleTimer.png

       

      Header 1

      <?xml version="1.0" encoding="UTF-8"?>

      <definitions id="Definition"

                   targetNamespace="http://www.jboss.org/drools"

                   typeLanguage="http://www.java.com/javaTypes"

                   expressionLanguage="http://www.mvel.org/2.0"

                   xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"

                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                   xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"

                   xmlns:g="http://www.jboss.org/drools/flow/gpd"

                   xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"

                   xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"

                   xmlns:di="http://www.omg.org/spec/DD/20100524/DI"

                   xmlns:tns="http://www.jboss.org/drools">

       

        <process processType="Private" isExecutable="true" id="com.sample.bpmn" name="Sample Process" tns:packageName="defaultPackage" >

       

          <!-- nodes -->

          <startEvent id="_1" name="StartProcess" />

          <intermediateCatchEvent id="_2" name="Timer" >

            <timerEventDefinition>

              <timeDuration xsi:type="tFormalExpression">1000</timeDuration>

            </timerEventDefinition>

          </intermediateCatchEvent>

          <endEvent id="_3" name="End" >

              <terminateEventDefinition />

          </endEvent>

       

          <!-- connections -->

          <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />

          <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

       

        </process>

       

        <bpmndi:BPMNDiagram>

          <bpmndi:BPMNPlane bpmnElement="com.sample.bpmn" >

            <bpmndi:BPMNShape bpmnElement="_1" >

              <dc:Bounds x="42" y="42" width="48" height="48" />

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape bpmnElement="_2" >

              <dc:Bounds x="135" y="42" width="48" height="48" />

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape bpmnElement="_3" >

              <dc:Bounds x="224" y="43" width="48" height="48" />

            </bpmndi:BPMNShape>

            <bpmndi:BPMNEdge bpmnElement="_1-_2" >

              <di:waypoint x="66" y="66" />

              <di:waypoint x="159" y="66" />

            </bpmndi:BPMNEdge>

            <bpmndi:BPMNEdge bpmnElement="_2-_3" >

              <di:waypoint x="159" y="66" />

              <di:waypoint x="248" y="67" />

            </bpmndi:BPMNEdge>

          </bpmndi:BPMNPlane>

        </bpmndi:BPMNDiagram>

       

      </definitions>

        • 1. Re: Not terminating process if timer
          swiderski.maciej

          might be that timer has use scheduler thread pool and thus jvm is not terminating automatically, could you try dispose the ksession at the end to check if the jvm process with end?

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: Not terminating process if timer
            atran

            Hi,

             

            Thank you for your answer. I tried your solution in a script task before the end:

             

            StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) kcontext.getKnowledgeRuntime();
            ksession.dispose();
            

             

            However, the process terminated with an exception:

             

            ERROR instance.timer.TimerManager.execute  - Error when executing timer job
            org.drools.RuntimeDroolsException: Unexpected exception executing action org.jbpm.process.instance.event.DefaultSignalManager$SignalProcessInstanceAction@71b8b3bb
                at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:995)
                at org.drools.impl.StatefulKnowledgeSessionImpl.executeQueuedActions(StatefulKnowledgeSessionImpl.java:866)
                at org.jbpm.process.instance.event.DefaultSignalManager.signalEvent(DefaultSignalManager.java:90)
                at org.jbpm.process.instance.timer.TimerManager$ProcessJob.execute(TimerManager.java:323)
                at org.drools.time.SelfRemovalJob.execute(SelfRemovalJob.java:15)
                at org.drools.time.impl.DefaultTimerJobInstance.call(DefaultTimerJobInstance.java:51)
                at org.drools.time.impl.DefaultTimerJobInstance.call(DefaultTimerJobInstance.java:14)
                at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
                at java.util.concurrent.FutureTask.run(Unknown Source)
                at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
                at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                at java.lang.Thread.run(Unknown Source)
            Caused by: org.jbpm.workflow.instance.WorkflowRuntimeException: [fr.thales.services.jbpm.validationPattern.SimpleTimer:1 - Script:4] -- Illegal method call. This session was previously disposed.
                at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:132)
            

             

            I guess the timer thread just never ends?

            • 3. Re: Not terminating process if timer
              swiderski.maciej

              don't dispose the session when executing the process (like in script task) because it will kill the engine while it's running.

               

              Dispose the session once you get control back from ksession.startProcess() method. When using timer you could add some delay (like Thread.sleep) to allow timer to fire.

               

              HTH

              • 4. Re: Not terminating process if timer
                atran

                Thank you for your answer.

                 

                I did as mentionned this:

                 

                Thread.sleep(5000);
                ksession.dispose();
                

                 

                For a process that last around 1s. It works but has some drawbacks:

                1) I have to be sure about the maximum duration of a process and it is impossible for some process.

                2) Since the duration are approximative, I have to add some margins. I still get the exception if I dispose just before the end node.

                3) The process ends later than it should.

                 

                However, this timer issue seems not to happen when launched in jBPM-console.

                • 5. Re: Not terminating process if timer
                  swiderski.maciej

                  what I suggested is more for tests purpose where you know how long will it take to complete the process.

                   

                  As you noticed it does not happen in console because console keep the session (and the java process) active as long as the application is active. So when dispose session is completely up to you and your requirements.

                   

                  HTH

                  • 6. Re: Not terminating process if timer
                    atran

                    Isn't it possible to have the application stopped just after the process end? Just like the jbpm-console. I mean, the dispose() should be automatic at the terminate end event and it should kill whatever timer thread there is. So I believe this is a bug?

                    • 7. Re: Not terminating process if timer
                      swiderski.maciej

                      it depends on how you want to use ksession, some would like to have it disposed as soon as process completes (usually called session per process instance strategy) but in other cases you share same session between many process instances. So it's up to you to take appropriate actions based on your requirements. With that said, it's not a bug but intended behavior.

                       

                      HTH