cancel
Showing results for 
Search instead for 
Did you mean: 

getting Exception org.activiti.engine.ActivitiOptimisticLockingException

sharad
Champ in-the-making
Champ in-the-making
I am using Activiti 5.14. I have created one bpmn that contains multi instance subprocess and we have created Service task within subprocess. Only one process engine is running in our environment. We are getting org.activiti.engine.ActivitiOptimisticLockingException while enabled async property of subprocess and Service task.

When both Subprocess and Service Task async property is enabled then We are getting following errors

Exception in thread "pool-1-thread-1" Name :Hello_5
org.activiti.engine.ActivitiOptimisticLockingException: HistoricVariableInstanceEntity[id=15, name=nrOfActiveInstances, type=integer, longValue=3, textValue=3] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:562)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:444)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:170)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:117)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
   at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:744)

When only Service task async property is enabled then we get following Exception =>

   Exception in thread "pool-1-thread-3" org.activiti.engine.ActivitiOptimisticLockingException: ScopeExecution[11] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:562)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:444)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:170)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:117)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
   at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:744)

Some times we have also observe org.activiti.engine.ActivitiOptimisticLockingException: VariableInstanceEntity[id=18614, name=nrOfCompletedInstances, type=integer, longValue=1, textValue=1] was updated by another transaction concurrently
Error.

How do we resolve these exceptions ?
7 REPLIES 7

trademak
Star Contributor
Star Contributor
The problem is that with an async multi instance sub process + an async service task within that sub process, a service task can end concurrently within the multi instance scope. Is there a specific reason to make the service task async? Are they long running?

Best regards,

sharad
Champ in-the-making
Champ in-the-making
Yes, Service task are taking long time.  We want to run service task in asynce manner. When I set Multi instance -> Sequential attribute to true of Multi Instance Sub process then there was no Exceptions. In that case, service task are running on multiple thread but in a sequential manner even if I have set Asynchronous option for sub process and service task to true. We want to run those service task in async manner. 

How do we achieve async Multi instance sub process with async service task without any exception ?

Do we need to handle ActivitiOptimisticLockingException in our project ?

jorell
Champ in-the-making
Champ in-the-making
I am having the same issue. Was there any solution to this?

frederikherema1
Star Contributor
Star Contributor
If you run multi-instance service tasks asynchronously, you can indeed run into Optimistic lock exceptions, when 2 async executions end about the same time. If you need to do long-running parallel execution, maybe you can take a look at integrating Camel, for example.

Having long-running stuff happening in a ServiceTask will keep the transaction open. It can result in transaction timeouts or (in case transaction timeout > 5 minutes) have the job be considered "hanging", having the job unlocked and retried by the job-executor…

box
Champ in-the-making
Champ in-the-making
I am having the same issue. firstly I find the Job lock time is 5min but our service tasks remain unfinished, so  set the JobExecutor lock time to larger(60min),concurrent is disappeared,is this work  ? thanks

trademak
Star Contributor
Star Contributor
Which version of Activiti are you using? Since version 5.17 we improved the job executor with a new async executor. Did you take a look at that?

Best regards,

box
Champ in-the-making
Champ in-the-making
yes ,I know in version 5.17 job executor with a new async executor which is good, but currently we using Activiti 5.14,we guarantee the execution variables only readable after set.   In multi subprocess ,when multi thead runing a async service task ActivitiOptimisticLockingException happen. so we set the lock time to 60min,It seem work, but I not sure is ActivitiOptimisticLockingException  may happen where in other special scene?