Getting OptimisticLockingException and one of the child job(callActivity) executing twice

I get this error when I call a more than one CallActivity from parallel gateway, also one call activity service executing twice and process not ending.
also how to set retry flag to 0.

2019-10-09 22:35:21 INFO AbstractBpmnActivityBehaviorImpl - Job status : true
2019-10-09 22:35:21 INFO AbstractBpmnActivityBehaviorImpl - AbstractBpmnActivityBehaviorImpl.execute() End
2019-10-09 22:35:22 WARN jobexecutor - ENGINE-14006 Exception while executing job 98c8fb01-eb06-11e9-87a7-2eb9c00bf035:
org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of ‘UPDATE VariableInstanceEntity[98c8accf-eb06-11e9-87a7-2eb9c00bf035]’ failed. Entity was updated by another transaction concurrently.
at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.concurrentUpdateDbEntityException(EnginePersistenceLogger.java:132)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.handleOptimisticLockingException(DbEntityManager.java:484)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.checkFlushResults(DbEntityManager.java:443)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:360)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:318)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:290)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:203)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:132)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Hey @apvenkatesan,

it looks like your Call Activities try to update the same process variable.
Since they are executed in parallel, this might lead to the exception you are getting here.
I’d encourage you to read more about this in the documentation.

Handling this really much depends on what variable you are altering in those activities and what you want to achieve with it.

Best,
Tobias

thanks tmetzke,

we just get the processvariable by runtimeService.getVariables(executionId) and update current job status.

Map<String, Object> processVariableMap1 = runtimeService.getVariables(executionId);
processVariableMap1.put(GlobalConstants.CURRENT_JOB_STATUS, false);
runtimeService.signal(executionId, processVariableMap1);

every callactivity is separate process and have the separate execution Id.

Hey @apvenkatesan,

could you state where exactly you are calling this code?

Also, is there a specific reason you are using the RuntimeService#signal method here? Maybe RuntimeService#setVariable or RuntimeService#setVariableLocal would be more suited in your current situation.

Best,
Tobias

thanks @tmetzke
This issue resolved now.

it happened due to Transaction Boundaries issue. after adding CamundaAsyncBefore="true"in some service task. working fine.

Thanks for letting us know that you found a solution! :slight_smile: