cancel
Showing results for 
Search instead for 
Did you mean: 

deadlock with basic multithreaded usertask test

jsher
Champ in-the-making
Champ in-the-making
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
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
org.h2.jdbc.JdbcSQLException

Don't use H2 when you want to to multi-threaded tests. H2 uses a lot of table-locks when only row-locks are needed. H2 is used because of it's speed in testing, but NEVER as production database. I'm confident that the same test won't block on mysql, postgres or any other DB we support.

jsher
Champ in-the-making
Champ in-the-making
Many thanks Frederik. I'll repeat tests with 'real' DB  Smiley Happy

meyerd
Champ on-the-rise
Champ on-the-rise
In h2, use MVCC=true

jsher
Champ in-the-making
Champ in-the-making
Thanks Daniel - that worked very nicely.

Regards
    James