AnsweredAssumed Answered

OptimisticLocking exception when try to update execution-variable

Question asked by shreyashp on Feb 7, 2016
Latest reply on Feb 9, 2016 by jbarrez
Hi,
I have setup a spring activiti engine.
I do a ProcessEngines.getDefaultProcessEngine(), will i get the same spring engine instance ?
How many job-executors will i have ? (i have my default job-executor turned on in config, async-executor is off)

Now the issue:
I startProceInstanceByKey(), and set a variable named 'envelop' in variableMap.
I have a process which has a service task.
1. This service task delegate (of type TaskActivityBehavior) puts a JMS message on ActiveMQ and a MessageListener reads it and makes REST call to external service.
2. The external service returns response via an REST end point in my system.
3. During this time my service task is waiting for a signal.
4. I am trying to update the value of variable 'envelop' with response received from external service. I use ProcessEngines.getDefaultProcessEngine().getRuntimeService().setVariable("envelop",newValue);
5. I signal the waiting serviceTask using the stored executionID. I use ProcessEngines.getDefaultProcessEngine().getRuntimeService().signal(envelop.getExecutionId());

I ran above process to spawn 100 processInstances. Out of which 96 succeeded, but 4 failed.
All four had same reason. In Step 4 above, while updating the execution variable it throws OptimisticLocking error as below:
org.activiti.engine.ActivitiOptimisticLockingException: ByteArrayEntity[id=290, name=var-envelop, size=335] was updated by another transaction concurrently.

Kindly help, my envelop variable is associated with different executionID, there is no case where someone else will update it in another transaction.

Outcomes