org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'DELETE MessageEntity[9aba61f6-7889-11ea-9059-acde48001122]' failed

Hello everyone,
I am little newbie to Camunda and exploring version 7.11 and running with spring boot 2.1.1.RELEASE.

My process model is quite straight forward and has couple of user tasks, 1 service task (invoking HTTP endpoint) and one task at the end that only waits for 20 seconds (using thread.sleep) before completing the workflow.

I am noticing intermittent error as listed below. I am using all default config for job executor. This error comes up at my last task, which does nothing but Thread.sleep(20000);. Before this, I have multiple user tasks, which are marked completed using REST invocations and no errors initially.

org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'DELETE MessageEntity[9aba61f6-7889-11ea-9059-acde48001122]' 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.handleOptimisticLockingException(
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.checkFlushResults(
	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(
	at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(
	at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(
	at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.base/java.util.concurrent.ThreadPoolExecutor$
	at java.base/

Also, I have created a custom bpmn parse listener to apply all to of my workflows.

public class AsyncExecutionEventListener extends AbstractBpmnParseListener {
    public void parseStartEvent(Element startEventElement, ScopeImpl scope,
                                ActivityImpl startEventActivity) {

    public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl serviceTaskActivity) {

    public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl userTaskActivity) {

Can anyone point me in right direction?

to fully understand whats going on i suggest reading the best practice guide on how threads work within the engine.

Thank you Niall for sharing this link. I’ve gone through this link and I still don’t get reasoning behind this intermittent failures.

Few points here.

  • I am using exclusive (default) jobs, which is meant not to raise this optimistic locking exception
  • I dont have any parallel paths either
  • I don’t have external tasks, but I do have user tasks, which are marked completed using camunda API successfully. Issue comes up when I am running a simple task, which does nothing but just simulates long running (as much 20-50 seconds) using thread.sleep and that causes this failure.