cancel
Showing results for 
Search instead for 
Did you mean: 

org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[] was updated by another transaction concurrently

aman1
Champ in-the-making
Champ in-the-making
I get a Optimistic lock exception in the scenario where the timer expires i.e. 'waitForUpdate' takes more than 10 seconds.
At this stage the workflow continues with the next step defined with boundaryEvent 'setDefaultIfNoDispatchUpdate'.
Now the response is received after 20 seconds (say). It signals back the workflow , at this stage i get the above exception.
Anything which i am doing wrong. Thanks.
The exception trace below.

[Exception] org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[…] was updated by another transaction concurrently
org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[…] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession$DeletePersistentObjectOperation.execute(DbSqlSession.java:239)
   at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:668)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:462)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:168)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:115)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:70)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
   at org.activiti.engine.impl.RuntimeServiceImpl.signal(RuntimeServiceImpl.java:173)






3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
Do you have multiple engines running on the same DB? If so, this can be ignored, as it' one of the 2 job-executors that is getting an exception because the timer is already executed by the other one. If it's not the case, it means that while the timer 'fires', another thread (possibly your app) has completed a task/signalled/… that particular process, before the "timer fire" transaction is committed. The timer-execution is rolled back, so it actually never happened because the process has moved on since.

aman1
Champ in-the-making
Champ in-the-making
<receiveTask id="waitForDispatchUpdate" />
  <boundaryEvent attachedToRef="waitForDispatchUpdate"
   id="setDefaultIfNoDispatchUpdate">
   <timerEventDefinition>
    <timeDuration>PT20S</timeDuration>
   </timerEventDefinition>
  </boundaryEvent>
<sequenceFlow id="flow3" sourceRef="sendDispatchMessage"  targetRef="waitForDispatchUpdate"  />

<sequenceFlow id="flow8" sourceRef="setDefaultIfNoDispatchUpdate" targetRef="setColourToPink" />

Thanks for your reply.  I do not have multiple engines running.
After the 'sendDispatchMessage' the control  comes to RecieveTask and waits there for response . Suppose the response doesn't comes in 20S. Then flow 8 executes and goes thru this breanch setDefaultIfNoDispatchUpdate ->setColourToPink. At this stage i see that the Activiti updates its tables (TimerEntity) which is correct.
Now if the response comes back in java code , we have an api that tries to signal back the workflow bpmn that the response is recieved.
the code snippet to do this is below
Execution execution =runtimeService.createExecutionQuery()
    .processInstanceId(processId).activityId('waitForDispatchUpdate')
    .singleResult();
if (execution != null) {
  runtimeService.signal(execution.getId());
}
Should this execution not be null as the 'waitForDispatchUpdate' has already expired now. As it doesn't return null and proceed to execute runtimeService.signal(execution.getId()) , it throws a Optimistic Lock exception on the TimerEntity.
My point is that the execution should have been returnned null as the timer had expired. Please suggest.
Thanks

trademak
Star Contributor
Star Contributor
With only part of the process definition listed it's difficult to get a full understanding of the issue.
Can you create a unit test showing your problem or include the full process definition and show exactly what Java code you are executing?

Best regards,