AnsweredAssumed Answered

deadlock with basic multithreaded usertask test

Question asked by jsher on Dec 19, 2012
Latest reply on Dec 19, 2012 by jsher
Hi, I hope someone can help with a deadlock I am seeing with a basic multithreaded test which interacts with a usertask.
I have a simple process with a single usertask. Attached is maven project if anyone would like to try it out for themselves.

I run N threads each of which start a process instance, get the active task for its process instance, and completes it.
I am using Contiperf to do basic multithreaded load test. With 1 thread all is well.
Successfully deployed 'target/classes/bpm/test/activiti/simple/Simple10_usertask.bpmn20.xml'
bpm.test.activiti.ActivitiTests.testSimple1_usertask
samples: 1659
max:     98
average: 5.54249547920434
median:  4
Rate = 165.30490235153448/s
However with 2 threads there is deadlock
Successfully deployed 'target/classes/bpm/test/activiti/simple/Simple10_usertask.bpmn20.xml'
bpm.test.activiti.ActivitiTests.testSimple1_usertask
Dec 19, 2012 10:04:02 AM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.h2.jdbc.JdbcSQLException: Deadlock detected. The current transaction was rolled back. Details: "
Session #2 (user: SA) is waiting to lock PUBLIC.ACT_RU_TASK while locking PUBLIC.ACT_RU_EXECUTION (exclusive).
Session #4 (user: SA) is waiting to lock PUBLIC.ACT_RU_EXECUTION while locking PUBLIC.ACT_RU_TASK (exclusive)."; SQL statement:
delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ? [40001-132]
### The error may involve org.activiti.engine.impl.persistence.entity.ExecutionEntity.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
### Cause: org.h2.jdbc.JdbcSQLException: Deadlock detected. The current transaction was rolled back. Details: "
Session #2 (user: SA) is waiting to lock PUBLIC.ACT_RU_TASK while locking PUBLIC.ACT_RU_EXECUTION (exclusive).
Session #4 (user: SA) is waiting to lock PUBLIC.ACT_RU_EXECUTION while locking PUBLIC.ACT_RU_TASK (exclusive)."; SQL statement:
delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ? [40001-132]
This is code for specific test (the number of threads is specified in the annotation)
   @Test
    @PerfTest(duration = 10000, threads = 2)
   public void testSimple1_usertask() {
      Map<String, Object> processParameters = new HashMap<String, Object>();
      ProcessInstance processInstance = runtimeService.startProcessInstanceById(simple1_usertask.getId(), processParameters);
      Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
      assertNotNull(task);
      taskService.complete(task.getId());
       processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
       assertNull(processInstance);
   }

Thanks
    James

Outcomes