Discussion:
[jboss-user] [jBPM] - Not terminating process if timer
Antoine T
2013-03-28 09:11:47 UTC
Permalink
Antoine T [https://community.jboss.org/people/atran] created the discussion

"Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/805231#805231

--------------------------------------------------------------
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
Loading Image... Loading Image...

FigB: Simple Timer:
Loading Image... Loading Image...

|| *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> |
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/805231#805231]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-03-29 16:33:30 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/805539#805539

--------------------------------------------------------------
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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/805539#805539]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Antoine T
2013-04-02 07:58:29 UTC
Permalink
Antoine T [https://community.jboss.org/people/atran] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/805922#805922

--------------------------------------------------------------
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$***@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?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/805922#805922]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-04-04 10:03:24 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/806408#806408

--------------------------------------------------------------
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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/806408#806408]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Antoine T
2013-04-04 11:26:06 UTC
Permalink
Antoine T [https://community.jboss.org/people/atran] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/806433#806433

--------------------------------------------------------------
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.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/806433#806433]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-04-04 16:44:08 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/806533#806533

--------------------------------------------------------------
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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/806533#806533]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Antoine T
2013-04-09 08:08:11 UTC
Permalink
Antoine T [https://community.jboss.org/people/atran] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/807143#807143

--------------------------------------------------------------
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?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/807143#807143]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-04-10 06:05:52 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: Not terminating process if timer"

To view the discussion, visit: https://community.jboss.org/message/807335#807335

--------------------------------------------------------------
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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/807335#807335]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...