cancel
Showing results for 
Search instead for 
Did you mean: 

org.activiti.engine.ActivitiOptimisticLockingException: JobEntity

soaguy
Champ in-the-making
Champ in-the-making
Hi all,
         I have 2 Activiti (v5.18) engines instances pointed to the same database. I have a java delegate serviceTask that has async='true'.  The java delegate is straighforward as it just inserts a row to an application table. When I test will higher message count, I see this exception below.


org.activiti.engine.ActivitiOptimisticLockingException: JobEntity [id=45926] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession$CheckedDeleteOperation.execute(DbSqlSession.java:294)
   at org.activiti.engine.impl.db.DbSqlSession.flushRegularDeletes(DbSqlSession.java:921)
   at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:887)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:612)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:211)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:137)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
   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.asyncexecutor.ExecuteAsyncRunnable.run(ExecuteAsyncRunnable.java:69)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)


I understand the async step creates a job and the job is executed on a separate thread, but this is causing duplicate insertions into the app table. For example when I test with 50 messages, I see this exception in the log and sometimes 62 rows in the app table. The count on the ACT_HI_PROCINST is still 50 though. Can someone please explain what is going on and how to handle this?

Thanks
Clement
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
That probably means the javadelegate logic you have is not transactional?
When an exception occurs, Activiti does a roll back of the transaction, if your jdbc code is not part of that transaction, then it doesn't know it has to roll back.