Exception when multi-instance service task itself inside a loop

cancel
Showing results for 
Search instead for 
Did you mean: 
yevgenyl
Active Member

Exception when multi-instance service task itself inside a loop

Jump to solution

I have the below process. In my process there is a multi-instance service task that itself is a part of a loop.

The issue is that I'm getting the below exception after the process is finished.

If I'll make Service Task 3 not to be multi-instanced or if Service Task 3 will not be part of the bigger loop, then I'll not get the exception, so the exception is happening specifically for the case I mentioned. 

org.activiti.engine.impl.pvm.PvmException: already taking a transition
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:453) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:438) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOutgoingBehavior(BpmnActivityBehavior.java:140) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDefaultOutgoingBehavior(BpmnActivityBehavior.java:66) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:44) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior.leave(SequentialMultiInstanceBehavior.java:75) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.execute(MultiInstanceActivityBehavior.java:98) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior.execute(SequentialMultiInstanceBehavior.java:90) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) ~[activiti-engine-5.22.0.jar:5.22.0]

The 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:xsd="http://www.w3.org/2001/XMLSchema" 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="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<serviceTask id="servicetask1" name="Service Task 1" activiti:delegateExpression="${serviceTask1}"></serviceTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<serviceTask id="servicetask2" name="Service Task 2" activiti:delegateExpression="${serviceTask2}"></serviceTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="exclusivegateway1"></sequenceFlow>
<sequenceFlow id="flow3" name="list not empty" sourceRef="exclusivegateway1" targetRef="servicetask2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${!myList.isEmpty()}]]></conditionExpression>
</sequenceFlow>
<serviceTask id="servicetask3" name="Service Task 3" activiti:delegateExpression="${serviceTask3}">
<multiInstanceLoopCharacteristics isSequential="true" activiti:collection="myList" activiti:elementVariable="element"></multiInstanceLoopCharacteristics>
</serviceTask>
<sequenceFlow id="flow5" sourceRef="servicetask2" targetRef="servicetask3"></sequenceFlow>
<sequenceFlow id="flow6" name="list empty" sourceRef="exclusivegateway1" targetRef="endevent1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${myList.isEmpty()}]]></conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="180.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="443.0" y="360.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="280.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
<omgdc:Bounds height="55.0" width="105.0" x="576.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="440.0" y="247.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">
<omgdc:Bounds height="55.0" width="105.0" x="576.0" y="130.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="215.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="280.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="385.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="440.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="480.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="576.0" y="267.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="489.0" y="267.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="628.0" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="628.0" y="185.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="460.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="460.0" y="360.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="470.0" y="309.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

How to solve it please?

1 Solution

Accepted Solutions
yevgenyl
Active Member

Re: Exception when multi-instance service task itself inside a loop

Jump to solution

So this is a known issue. if in some point in the process the list, that the multi-instance service task is using, becomes empty - then we'll get this exception.

https://github.com/Activiti/Activiti/issues/748

View solution in original post

3 Replies
bassam_al-saror
Alfresco Employee

Re: Exception when multi-instance service task itself inside a loop

Jump to solution

Can you provide some code that can be use to reproduce the issue?

yevgenyl
Active Member

Re: Exception when multi-instance service task itself inside a loop

Jump to solution

Service Task 2 and Service Task 3 are doing nothing.

Service Task 1 is below.

"index" is just a variable I'm passing when starting the flow.

public class ServiceTask1 implements JavaDelegate
{

@Override
public void execute(DelegateExecution execution) throws Exception
{
int index = execution.getVariable("index" , Integer.class);
List<String> myList = new ArrayList<String>();

if(index > 0)
{
for(int i = 0 ; i<index ; i++)
{
myList.add("test " + i);
}
index--;
execution.setVariable("index", index);
}

execution.setVariable("myList", myList);

}

yevgenyl
Active Member

Re: Exception when multi-instance service task itself inside a loop

Jump to solution

So this is a known issue. if in some point in the process the list, that the multi-instance service task is using, becomes empty - then we'll get this exception.

https://github.com/Activiti/Activiti/issues/748