Dear Community,
I am trying to suspend a process instance in one of its service tasks. I did it like described in Camunda synchronous process instance wont suspend - Stack Overflow
However, doing it like that I get an optimistic locking exception. Apparently, when I suspend the process instance at the same time the process engine finishes the Java Delegate and wants to write that to the DB as well.
So, as a workaround I included a Thread#sleep for testing purposes. Now the process engine behaves funny. The Java Delegate repeats getting executed. Why is that?
The code of my JavaDelegate
@Service
public class DataFetchDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
String pid = execution.getProcessInstanceId();
VariableMap variables = Variables//
.createVariables()//
.putValue("processInstanceToSuspend", pid);
runtimeService.startProcessInstanceByKey("Process_Suspension", variables);
System.out.println("Suspending Process Instance ...");
runtimeService//
.updateProcessInstanceSuspensionState()//
.byProcessInstanceId(pid)//
.suspend();
Thread.sleep(5000);
}
}
Any hint is appreciated.