05-09-2017 09:27 AM
Hi,
We have a design like One Service Task is followed by next Service Task. Here it throws below error when the second Service task is initiated:
2017-05-09 15:50:16,341 DEBUG [org.activiti.engine.impl.db.DbSqlSession] (pool-5-thread-2) executing: delete ConcurrentExecution[2119210]
2017-05-09 15:50:16,342 DEBUG [org.activiti.engine.impl.persistence.entity.ExecutionEntity.deleteExecution] (pool-5-thread-2) ooo Using Connection [Transaction-aware proxy for target Connection [jdbc:jtds:sqlserver://indiadev02;DatabaseName=awomdb;SelectMethod=Cursor, UserName=dmsdb, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase]]
2017-05-09 15:50:16,342 DEBUG [org.activiti.engine.impl.persistence.entity.ExecutionEntity.deleteExecution] (pool-5-thread-2) ==> Preparing: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
2017-05-09 15:50:16,342 DEBUG [org.activiti.engine.impl.persistence.entity.ExecutionEntity.deleteExecution] (pool-5-thread-2) ==> Parameters: 2119210(String), 3(Integer)
2017-05-09 15:50:16,344 DEBUG [org.activiti.engine.impl.persistence.entity.ExecutionEntity.deleteExecution] (pool-5-thread-2) <== Updates: 0
2017-05-09 15:50:16,344 DEBUG [org.activiti.engine.impl.interceptor.CommandContext] (pool-5-thread-2) Optimistic locking exception : org.activiti.engine.ActivitiOptimisticLockingException: ConcurrentExecution[2119210] was updated by another transaction concurrently
2017-05-09 15:50:16,344 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] (pool-5-thread-2) Participating in existing transaction
2017-05-09 15:50:16,346 DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] (pool-5-thread-2) Closing JDBC Connection [Transaction-aware proxy for target Connection [jdbc:jtds:sqlserver://indiadev02;DatabaseName=awomdb;SelectMethod=Cursor, UserName=dmsdb, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase]]
2017-05-09 15:50:16,346 DEBUG [org.springframework.transaction.support.TransactionTemplate] (pool-5-thread-2) Initiating transaction rollback on application exception: org.activiti.engine.ActivitiOptimisticLockingException: ConcurrentExecution[2119210] was updated by another transaction concurrently
at org.activiti.engine.impl.db.DbSqlSession$CheckedDeleteOperation.execute(DbSqlSession.java:273)
at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:647)
at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:504)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:182)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:128)
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:37)
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:52)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
------------------------------------------------------------------------------------------------------------------
2017-05-09 15:50:16,353 ERROR [org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable] (pool-5-thread-2) exception during job execution: ConcurrentExecution[2119210] was updated by another transaction concurrently: org.activiti.engine.ActivitiOptimisticLockingException: ConcurrentExecution[2119210] was updated by another transaction concurrently
at org.activiti.engine.impl.db.DbSqlSession$CheckedDeleteOperation.execute(DbSqlSession.java:273)
at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:647)
at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:504)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:182)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:128)
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:37)
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:52)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
NOTE: We have used Locking mechanism to ensure there are no concurrent threads running, which works pretty well-one after another.
But the problem I find here is: Transaction !! Transaction is not committed somehow I think, but need solution to make it work. Any help will be appreciated.
Thanks,
Ami
05-09-2017 07:55 PM
Hi Ami,
Do you always get this error "ActivitiOptimisticLockingException" from the second service task? Is it easy to reproduce this error in a unit test and share it?
Ciju
05-10-2017 02:03 AM
Hi Ciju,
Thanks for reply. I am always persistently getting the same exception all the time when second Service task tried to update in activiti db, and during that I don't whom's but some other task's transaction is updating in db(whose transaction might not be yet committed).
Scenario is like, out of 10, one Design is stuck at the second service task, due to this issue, all 9 gets completed successfully.
For User task, we call TaskService.complete method to complete the user task which initiates the flow of Service task, So I doubt that the complete method of Activiti's class-TaskService, might return back the call without committing the transaction. Is it so?
QUESTION:Then how can I ensure that the transaction of user task is committed or not?which class should I use for that assurance?
Because I'm damn sure for Service task, we ensure that afterCommit() method is used and then next waiting task gets lock.
It would not be easy to create Unit test for whole Design that I have shared in the image attached.
Any help would be appreciated.
Thanks,
Ami
05-10-2017 09:36 AM
Have you attempted to make the second service task "asynchronous".
This should push it onto the job queue which will permit the original thread to release and commit the transaction.
Pretty standard issue, optimistic locking issues should be resolved in the version 6 engine (that was a design goal).
Greg
05-10-2017 09:46 AM
Hi Greg,
By default our all service tasks are "asynchronous" and hence both gets pushed into job queue.
So do you think we need to make any changes out here to make this scenario work?
Suggest me some approach.
Thanks,
Ami
05-10-2017 09:53 AM
Ok, so I can't be certain without seeing a thread dump but it's possible that with both service tasks on the queue they are being picked up in the same scheduler "scan" and so the services are being completed at the same time.
Just for testing purposes and to see if behavior changes, try making Service Task 1 synchronous (so it is executed on the servlet thread that processed the user task).
Not saying this will absolutely work since the error is coming out of the database and we essentially have a race condition. But worth a try.
Greg
05-11-2017 08:54 AM
Hi Greg,
I have tried the stated solution, but didn't worked. Still getting ActivitiOptimisticLockingException.
Thanks,
Ami
05-11-2017 11:44 AM
Yeah, no real surprise.
Can you not combine the two services into a single service call?
Explore our Alfresco products with the links below. Use labels to filter content by product module.