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?
Each JavaDelegateis executed by a job executor. A job that gets stuck, may prevent the completion of the process. Therefore, a timeout is implemented. This timeout is configurable via the property camunda.bpm.job-execution.lock-time-in-millis the default is 300000. Can it be, that the lock time is too restrictive?
Is your delegate called by a service task?
I assume that the following is happening:
Your delegate is called
You suspend the process
You add the Thread sleep
Your delegate completes BUT fails because its process instance has been suspended and completing a task would advance the token, which is an invalid operation for suspended processes. Since the delegate failed, the service task will be repeated.
You can try using a TaskListener or an ExecutionListener.
He does not say anything about the event subprocess. So, as far as I understand the fact that the suspension is triggered in an event subprocess should not have any influence. Am I right or am I missing something?
I set an async continuation before at the subsequent activity. However, the SuspensionDelegate keeps repeating itself.
You could “Message Throw” to a different process, with a message containing your process id.
This other process starts on “Message Receive” and suspends the process with the ID in the message.