cancel
Showing results for 
Search instead for 
Did you mean: 

ActivitiOptimisticException with single JobExecutor

sushantmahajan
Champ in-the-making
Champ in-the-making
We have written a custom code overriding Locking for jobs in acquireJobCmd. The application uses Hibernate for database connection. Sometimes we experience ActivitiOptimisticLockingException for a job and that job gets stuck with a lock owner till it reaches lock expiration time. The exception that occurs is:

ERROR pool-1-thread-5 org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable - exception during job execution: ProcessInstance[d108d1cf-ada6-11e4-9e28-c2e2b6a89800] was updated by another transaction concurrently
org.activiti.engine.ActivitiOptimisticLockingException: ProcessInstance[d108d1cf-ada6-11e4-9e28-c2e2b6a89800] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:777)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:588)
   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:130)
   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.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:52)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

We have not accessed that job/process instance other after locking it. What may be the reason we get this Exception even when we are on Single Server environment?
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
If you are on single node, you shouldn't see this. Are you changing data of the job yourself when the job is being executed? That could explain the optimistic locking problem.

We are experiencing ActivitOptimisticexception two cases on single server.

1. When we try to delete a running job. Please suggest how to carefully wait before calling runTimeService.deleteProcessInstance(String processInstanceId, String deleteReason).

2. We have customised AcquiredJobCommand, that in execute method we set its lock owner, lock expiration time and retries and then add the job to AcquiredJobs. What among these be a reason for this exception? Please suggest.

1. What's the reason for wanting to delete a process instance while the job is running? The logic being executed in the job will remain running anyways, so it's best to delete the process instance after the job has stopped running.

2. Can you explain the reasoning behing changing the command? Are you using the new async job executor or the other job executor? When do you see the ActivitiOptimisticLockException occurring?

Best regards,