AnsweredAssumed Answered

Multi-instance sub process completion concurrency problem

Question asked by ochrons on May 18, 2012
Latest reply on May 23, 2012 by ochrons
I've got a multi-instance sub process defined which contains Java service tasks and timers. The timers are used for polling an external service (through a Java service task). If the results are not ready, the process will go back into the timer to wait.

Now, because of the timers, Activiti will use its internal thread pool to run the different executions in parallel in different threads. This is ok until the processes start getting completed at the same time. At completion, there are sometimes exceptions:

18-May-2012 20:37:35 org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiOptimisticLockingException: VariableInstanceEntity[17] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(

The variable (17) that it being updated is actually the nrOfActiveInstances counter for the sub process. This behavior seems quite silly to me, since it's nothing I can control directly.

I suppose I could work around this issue by introducing a Java Receive Task just before the sub process end event, to synchronize all Activiti controlled threads into my own thread.

Any real solutions to this problem?

- Otto