I’m having a similar problem now. I have two parallel service tasks which both check, if the other one has set its variable already and if it has, “success” is printed. Here are the process definitions:
<bpmn:process id=“TestParallelVariableChangeParentProcess” name=“TestParallelVariableChangeParentProcess” isExecutable=“true”>
<bpmn:startEvent id="Start" name="Start" />
<bpmn:parallelGateway id="Fork" />
<bpmn:callActivity id="TestParallelVariableChangeChildProcess1" name="TestParallelVariableChangeChildProcess1" calledElement="TestParallelVariableChangeChildProcess" >
<bpmn:extensionElements>
<camunda:in variables="all" />
<camunda:out variables="all" />
<camunda:inputOutput>
<camunda:inputParameter name="thisname">p1</camunda:inputParameter>
<camunda:inputParameter name="othername">p2</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:callActivity id="TestParallelVariableChangeChildProcess2" name="TestParallelVariableChangeChildProcess2" calledElement="TestParallelVariableChangeChildProcess" >
<bpmn:extensionElements>
<camunda:in variables="all" />
<camunda:out variables="all" />
<camunda:inputOutput>
<camunda:inputParameter name="thisname">p2</camunda:inputParameter>
<camunda:inputParameter name="othername">p1</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:parallelGateway id="Join" />
<bpmn:endEvent id="End" name="End" />
<bpmn:sequenceFlow id="ToFork" name=""
sourceRef="Start"
targetRef="Fork" />
<bpmn:sequenceFlow id="ToTestParallelVariableChangeChildProcess1" name=""
sourceRef="Fork"
targetRef="TestParallelVariableChangeChildProcess1" />
<bpmn:sequenceFlow id="FromTestParallelVariableChangeChildProcess1" name=""
sourceRef="TestParallelVariableChangeChildProcess1"
targetRef="Join" />
<bpmn:sequenceFlow id="ToTestParallelVariableChangeChildProcess2" name=""
sourceRef="Fork"
targetRef="TestParallelVariableChangeChildProcess2" />
<bpmn:sequenceFlow id="FromTestParallelVariableChangeChildProcess2" name=""
sourceRef="TestParallelVariableChangeChildProcess2"
targetRef="Join" />
<bpmn:sequenceFlow id="ToEnd" name=""
sourceRef="Join"
targetRef="End" />
</bpmn:process>
<bpmn:process id=“TestParallelVariableChangeChildProcess” name=“TestParallelVariableChangeChildProcess” isExecutable=“true”>
<bpmn:startEvent id="Start" name="Start" camunda:asyncBefore="true" />
<bpmn:serviceTask id="SetVariable" name="SetVariable" camunda:class="test.TestParallelVariableChangeServiceTask" camunda:asyncAfter="true" />
<bpmn:endEvent id="End" name="End" />
<bpmn:sequenceFlow id="ToSetVariable" name=""
sourceRef="Start"
targetRef="SetVariable" />
<bpmn:sequenceFlow id="ToEnd" name=""
sourceRef="SetVariable"
targetRef="End" />
</bpmn:process>
and this JavaDelegate:
package test;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
public class TestParallelVariableChangeServiceTask implements JavaDelegate {
private static final Object LOCK = new Object();
@Override
public void execute(DelegateExecution execution) throws Exception {
String thisName = (String)execution.getVariable("thisname");
String otherName = (String)execution.getVariable("othername");
DelegateExecution superProcessInstance = execution.getProcessInstance().getSuperExecution().getProcessInstance();
synchronized (LOCK) {
if (superProcessInstance.hasVariable(otherName)) {
System.out.println("success");
} else {
System.out.println(thisName + " was not successful");
superProcessInstance.setVariable(thisName, true);
}
}
}
}
The output is
p1 was not successful
p2 was not successful
and two OptimisticLockingExceptions are thrown:
ENGINE-14006 Exception while executing job 98245: : org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of ‘UPDATE VariableInstanceEntity[98203]’ failed. Entity was updated by another transaction concurrently.
[stack trace]
ENGINE-14006 Exception while executing job 98245: : org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of ‘UPDATE VariableInstanceEntity[98203]’ failed. Entity was updated by another transaction concurrently.
[stack trace]
Is there anything I can do to make sure, that “success” is being printed?
The original problem is, that I have two or more parallel paths that are only allowed to proceed to the join gateway after all paths have finished.