Camunda 7 parallel task is giving optimistic locking exception on nrOfCompletedInstances

We have a java delegate to make rest calls to microservices. When doing a parallel multiinstance activity I can see that the tasks are being done in parallel, and both complete successfully. But when the 2nd task completes I get the optimistic locking error :

org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'UPDATE VariableInstanceEntity[7730a196-615a-11ed-994e-0242a410105b]' failed. Entity was updated by another transaction concurrently.
	at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.concurrentUpdateDbEntityException(
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.handleConcurrentModification(
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(
	at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(
	at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(

When I look up that variable in the database this is what I get :

id_                                     rev_    type_     name_ 
7730a196-615a-11ed-994e-0242a410105b	2	    integer	  nrOfCompletedInstances

Why am I getting an optimistic lock exception on a variable that is used only for multi instance tasks?

Hi @edward_winston

How does the Asynchronous continuations look like on your multi instance activity? Have you unchecked the Exclusive checkbox?


I got this working by putting Asynchronous continuations on all items in a subprocess. This includes the start and end events and the one task in the subprocess. I had to use a parallel subprocess task since I needed to change the URL that is being invoked based on the contents of the input collection.

I can include a snippet showing the problematic part of my process if you are interested.


Have you tried setting Asynchronous After on the multi instance task? Also, what kind of jdbc driver are you using?

Check Parallel_execution in camunda bpmn - #18 by MaximMonin to understand a problem with locking.

For multiinsance jobs, it is best to create subprocess with task have async after flag