AnsweredAssumed Answered

Problem when increasing maxJobsPerAcquisition

Question asked by hugues on May 20, 2014
Latest reply on May 21, 2014 by jbarrez
I am evaluating usage of Activiti in our project.  I made a simple test Java app that embeds Activiti and creates process instances. The process definition includes a timer event, and I am testing how the JobExecutor deals with many jobs that have a same due date. I created 1000 instances, and they all have a user task with a timer boundary event with the exact same due date and time.
When maxJobsPerAcquisition is 1, everything goes very well: JobExecutor executes the jobs as fast as it can using its threads pool.
When I set maxJobsPerAcquisition to 3, some jobs fails into error, randomly.  The higher the maxJobsPerAcquisition, the more frequent I see jobs in error.
Note that I do have only one Activiti instance runnning (my test main app). I know that when multiple Activiti access the same DB, maxJobsPerAcuqisition should stay 1 because of locking problems. I was wondering if the problem here is due to locking or not.

The stack trace of one such job error is (I removed some lines to keep it shorter):

Exception in thread "pool-1-thread-8" org.activiti.engine.ActivitiException: Job 2575 failed
   at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(
   at org.activiti.engine.impl.interceptor.CommandInvoker.execute(
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
### The error may exist in org/activiti/db/mapping/entity/HistoricActivityInstance.xml
### The error may involve org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity.selectHistoricActivityInstancesByQueryCriteria
### The error occurred while executing a query
### SQL: select * from ( select a.*, ROWNUM rnum from (     select RES.*            from ACT_HI_ACTINST RES      WHERE  RES.EXECUTION_ID_ = ?                              and RES.ACT_ID_ = ?                                            and RES.END_TIME_ is null           order by RES.ID_ asc        ) a where ROWNUM < ?) where rnum  >= ?
### Cause: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(
   at org.activiti.engine.impl.db.DbSqlSession.selectListWithRawParameter(
   at org.activiti.engine.impl.db.DbSqlSession.selectList(
   at org.activiti.engine.impl.db.DbSqlSession.selectList(
   at org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntityManager.findHistoricActivityInstancesByQueryCriteria(
Caused by: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
   at org.apache.ibatis.datasource.pooled.PooledConnection.checkConnection(
   at org.apache.ibatis.datasource.pooled.PooledConnection.invoke(

I use an Oracle DB for persistence. I have default connection pool set-up.

Is this problem linked to db locking and maxJobsPerAcquisition value, or is it "simply" a connection pool issue ? Would the connection pool be too small when we increase the maxJobsPerAcquisition, and therefore the number of parallel job executions ?
Any hint will be welcome to help me searching the right direction.

Thanks a lot!