cancel
Showing results for 
Search instead for 
Did you mean: 

End Event Received by listener after cancelling.

vram
Champ in-the-making
Champ in-the-making
Hi,

I tried to cancel my task which was running currently.(I have a task with a sleep time in it. And when it was running I tried to cancel it) . I use the RunTimeService.deleteProcessInstance.

I could see the activiti job entries all deleted and my workflow is cancelled.

But,after the specified sleep time is completed, I could see activiti sending my listener an end event . I am totally puzzled . Could someone help as to how the end event is received even though all the job entries are deleted and my workflow is cancelled?

Thanks
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
I'm not following your use case. Could you post your process xml?

vram
Champ in-the-making
Champ in-the-making
Hi,

My BPMN xml is :

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="Myprocess4" name="myprocess4">
    <documentation>Place documentation for the 'myprocess4' process here.</documentation>
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <serviceTask id="servicetask1" name="Service Task" activiti:async="true" activiti:class="com.mikewidgets.helloWorld.HelloWorldTask"></serviceTask>
    <sequenceFlow id="flow2" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_Myprocess4">
    <bpmndi:BPMNPlane bpmnElement="Myprocess4" id="BPMNPlane_Myprocess4">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="170" y="110"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="330" y="200"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55" width="105" x="390" y="130"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="187" y="145"></omgdi:waypoint>
        <omgdi:waypoint x="273" y="151"></omgdi:waypoint>
        <omgdi:waypoint x="347" y="151"></omgdi:waypoint>
        <omgdi:waypoint x="349" y="151"></omgdi:waypoint>
        <omgdi:waypoint x="390" y="157"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="442" y="185"></omgdi:waypoint>
        <omgdi:waypoint x="347" y="200"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


This involves a service task. I started my workflow.This task has a sleep time specified in it. When the workflow was in the sleep , I tried to cancel the workflow using RunTimeService.deleteProcessInstance . All the job entries were deleted.

So , now the workflow should have aborted execution. But after the sleep time , I find the workflow task executing and also my execution listener receives a end event marking the completion .

jbarrez
Star Contributor
Star Contributor
ok, got it now. Indeed, service tasks are not interruptable. And indeed, the engine will finish the current step when the service task awakes, but the process instance won't continue.

What's the use case you're trying to implement?

vram
Champ in-the-making
Champ in-the-making
My workflow calls a service task which has a sleep time incorporated in it and then ends the process after completing the task.

When the task is waiting , I decide to end the process and hence call the deleteProcessInstance method.

After this,the jobs entries are deleted and my process instance is cancelled as expected.

But, after the specified sleep time is completed, the task proceeded to completion and the execution listener receives a end completion  event .The cancelled  process instance is now marked as complete which is wrong.


I would like to clarify as to why the activiti sends an end event to the listener after the workflow is cancelled?

Thanks

jbarrez
Star Contributor
Star Contributor
The problem is that the thread which is currently executing the service task doesn't know about the other thread cancelling the process.
It would require quite some thread juggling to fix that problem … something that we won't do in the forseeable future.
So I'm afraid it's not possible to cover your use case.

But on the other hand, the need for sleeps in your process does smell like bad design.
Why can't you use a wait state / signal combination to avoid the sleep?

vram
Champ in-the-making
Champ in-the-making
Thanks a lot jbarrez for clarifying and your inputs. I would change my code to have a wait. Thanks once again.