cancel
Showing results for 
Search instead for 
Did you mean: 

Handling the org.activiti.engine.ActivitiOptimisticLockingException

arunshenbagaraj
Champ in-the-making
Champ in-the-making
Hi There,

Hope u r doing good. Am using the activiti-engine version 5.17, in my workflow am using a parallel gateway with 5 service tasks running in parallel, all are exclusive jobs. Two jobs are failing with the below exception. When a service task fails, the service task starts executing from the beginning. I need to stop this, when a service task fails with the below exception, it should only try to update the db again rather than executing the service task itself again.

org.activiti.engine.ActivitiOptimisticLockingException: ProcessInstance[70004] was updated by another transaction concurrently
        at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:783)
        at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:594)
        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.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.asyncexecutor.ExecuteAsyncRunnable.run(ExecuteAsyncRunnable.java:73)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)

Please help me identifying the issue. Thanks in advance.
5 REPLIES 5

trademak
Star Contributor
Star Contributor
Hi Arun,

Only one service task can be executed when the task is set to exclusive. So if it's not able to get the process instance lock you will see the exception you mentioned. But the service task should not be executed in that case, because it will first try to get the process instance lock. So  are you sure this is an issue like you described?

Best regards,

arunshenbagaraj
Champ in-the-making
Champ in-the-making
Hi Tijis,

Yes, this an issue like i described. Please let me know if there are any workarounds to come over it. Thanks in advance.

jbarrez
Star Contributor
Star Contributor
Cold you create a simple unit test with a process that demonstrates the problem

arunshenbagaraj
Champ in-the-making
Champ in-the-making
Hello Barrez,

Please find below my process definition xml.
<code>
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="automation-workflow" name="automation-workflow" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <parallelGateway id="parallelgateway1" name="Parallel Gateway" activiti:async="true"></parallelGateway>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
    <serviceTask id="ETrustService" name="ETrustService" activiti:async="true" activiti:exclusive="false" activiti:class="com.workflow.task.ETrustService"></serviceTask>
    <serviceTask id="HPOVService" name="HPOVService" activiti:async="true" activiti:exclusive="false" activiti:class="com.workflow.task.HPOVService"></serviceTask>
    <serviceTask id="AvamarService" name="AvamarService" activiti:async="true" activiti:exclusive="false" activiti:class="com.workflow.task.AvamarService"></serviceTask>
    <serviceTask id="EncaseService" name="EncaseService" activiti:async="true" activiti:exclusive="false" activiti:class="com.workflow.task.EncaseService"></serviceTask>
    <serviceTask id="DPSUService" name="DPSUService" activiti:async="true" activiti:exclusive="false" activiti:class="com.workflow.task.DPSUService"></serviceTask>
    <sequenceFlow id="flow2" sourceRef="parallelgateway1" targetRef="ETrustService"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="HPOVService"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="parallelgateway1" targetRef="AvamarService"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="parallelgateway1" targetRef="EncaseService"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="parallelgateway1" targetRef="DPSUService"></sequenceFlow>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
<sequenceFlow id="flow7" sourceRef="ETrustService" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="HPOVService" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow9" sourceRef="AvamarService" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow10" sourceRef="EncaseService" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow11" sourceRef="DPSUService" targetRef="parallelgateway2"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow22" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow>
  </process>
</definitions>
</code>

I have five service tasks running in parallel. All the service tasks are completing their execution almost at the same time. At times two or three jobs failing with the message "ProcessInstance[115082] was updated by another transaction concurrently". After they fail, the activiti engine tries to run the service task again from the beginning for 3 times. Am using the activiti version 5.17. Please help.

jbarrez
Star Contributor
Star Contributor
This is expected behaviour: you have 5 tasks in parallel, all async. They all get their own thread and own database transaction. They will try to continue the process, all of them, and that is why you are seeing the optimistic locking. On itself, this is not a bad thing, as the jobs will be retried later on.
One option is to play with the exclusive attribute here, but that will also have as consequence you wont have things in parallel anymore.