AnsweredAssumed Answered

ActivitiOptimisticLockingException when updating HistoricVariableInstanceEntity

Question asked by eric.manuguerra on Nov 19, 2015
Hi everybody,

I am upgrading the Activti engine of a web application from 5.8 to 5.17.

I have applied the migration scripts to the database and performed the engine adjustments following the user guide.

I have activated the asynchronous job executor like this :

        <property name="jobExecutorActivate" value="false" />
        <property name="asyncExecutorEnabled" value="true" />
        <property name="asyncExecutorActivate" value="true" />

And configured it like this :

    <bean id="asyncExecutor" class="org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor">
        <property name="corePoolSize" value="10" />
        <property name="maxPoolSize" value="50" />
        <property name="keepAliveTime" value="3000" />
        <property name="queueSize" value="200" />
        <property name="maxTimerJobsPerAcquisition" value="1" />
        <property name="maxAsyncJobsDuePerAcquisition" value="1" />
        <property name="defaultAsyncJobAcquireWaitTimeInMillis" value="10000" />
        <property name="defaultTimerJobAcquireWaitTimeInMillis" value="10000" />
        <property name="timerLockTimeInMillis" value="60000" />
        <property name="asyncJobLockTimeInMillis" value="60000" />

When I restart the application server I get a lot of ActivitiOptimisticLockingException related to the update of "HistoricVariableInstanceEntity" :

Exception in thread "pool-23-thread-25" org.activiti.engine.ActivitiOptimisticLockingException: JobEntity [id=0a3ba96f-8ecd-11e5-95a6-02429bae1fe4] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(
   at org.activiti.engine.impl.db.DbSqlSession.flush(
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(
   at org.activiti.engine.impl.interceptor.CommandContext.close(
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(
   at org.activiti.spring.SpringTransactionInterceptor.execute(
   at java.util.concurrent.ThreadPoolExecutor.runWorker(
   at java.util.concurrent.ThreadPoolExecutor$

From the analysis I have performed I can see that, one of my workflows is updating the value of a result variable "tachEnCours" :

<serviceTask id="TS-NO-039" name="TS-NO-039 contrôler si tâches en cours pour la demande" activiti:expression="${notificationProcessusService.controlerTacheEnCoursOuStandBy(demandePrestationsReferenceId)}" activiti:resultVariableName="tachEnCours"></serviceTask>

The variable update is performed without any issue.

The variable value change is then recorded by the engine in the variable history (ACT_HI_VARINST table). But the update is performed by several concurrent threads resulting in optimistic lock exceptions.

I can also see this in the ACT_RU_JOB exception message :

HistoricVariableInstanceEntity[id=13871936, name=tachEnCours, revision=88, type=boolean, longValue=1] was updated by another transaction concurrently

The application is running fine, but generating a lot of these exceptions (100 per hour) always on the same HistoricVariableInstanceEntity.

Why is this history variable updated by multiple threads ?

How to solve this issue and get rid of these exceptions ?

Any help would be greatly appreciated.

With my best regards,