Using CallActivity

Hi Encho.

When I run the test without CallActivity (without multiinstance, without async) execution works fine. If you want to resolve it create a jUnit test to know exactly where the problem is.

The optimistic locking exception which is thrown:

[flowable-async-job-executor-thread-2] ERROR org.flowable.job.service.impl.asyncexecutor.DefaultAsyncRunnableExecutionExceptionHandler  - Job 50 failed
org.flowable.common.engine.api.FlowableOptimisticLockingException: HistoricVariableInstanceEntity[id=16, name=nrOfCompletedInstances, revision=0, type=integer, longValue=1, textValue=1] was updated by another transaction concurrently

The problem is that variable nrOfCompletedInstances is updated from each job. That’s why optimistic locking exception is thrown.
Solution proposal:

  1. Create async job in the loop. In that case you will avoid multiinstance behavior which is trying to update nrOfCompletedInstances
  2. change callActivity to synchronous and multiinstance to sequential. The first task in the subprocess is asynchronous. What I would expect is that jobs are generated and job executors will execute them in parallel.

Regards
Martin