AnsweredAssumed Answered

Serious multithreading problem with embedded Activiti

Question asked by gergelydombi on Jul 21, 2011
Latest reply on Jul 21, 2011 by ronald.van.kuijk
Hi guys!

We are using Activiti in our project. It was a very good experience so far for the whole team, both the product and
the documentation was great.

Our application has a Spring 3 / Hibernate backend and we use the Activiti engine embedded into our Spring configuration.
The Spring integration looked pretty good throughout the development of the application.

We are just before the handover phase and we ran an internal performance test. It was quite shocking that the Activiti engine began to throw Database Deadlock exceptions with as few as 4 concurrent users.

We analyzed our code thoroughly, and replaced our initial database choice with several other databases but the
problem remained.

We created a test case to separate our application logic from this weird multithreaded behaviour, and it show that in fact it is the Activiti engine that causes the deadlock. Our test case is pretty simple, a sequencial series of human tasks, service tasks and receive tasks (to force persistence in some cases). Our test code starts several threads to initialize one process instances per thread. A process variable is set prior to the start of the process that is used later in a boundary event (timer).

The full source code and executable binaries (with all the dependencies) of the test case can be downloaded from

We would be keen to create a JIRA issue on this, and would be happy to be involved in the fix.

Lock aquisition exception occurs in the following scenario:

### The error may involve org.activiti.engine.impl.persistence.entity.ExecutionEntity.insertExecution-Inline
### The error occurred while setting parameters
### Cause: org.hibernate.exception.LockAcquisitionException: Deadlock detected. The current transaction was rolled back. Details: "
Session #14 (user: SA) is waiting to lock PUBLIC.ACT_RU_VARIABLE while locking PUBLIC.ACT_RE_PROCDEF (shared), PUBLIC.ACT_RU_VARIABLE (shared), PUBLIC.ACT_RU_EXECUTION (exclusive).
Session #12 (user: SA) is waiting to lock PUBLIC.ACT_RU_EXECUTION while locking PUBLIC.ACT_RE_PROCDEF (shared), PUBLIC.ACT_RU_VARIABLE (shared)."; SQL statement:
    values (
    ) [40001-158]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(
at org.activiti.engine.impl.db.DbSqlSession.flushInserts(
at org.activiti.engine.impl.db.DbSqlSession.flush(
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(
at org.activiti.engine.impl.interceptor.CommandContext.close(
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(
at org.activiti.spring.SpringTransactionInterceptor.execute(
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(
at hu.sonrisa.example.service.impl.WorkflowServiceImpl.startProcess(