cancel
Showing results for 
Search instead for 
Did you mean: 

Error in async process- Error while closing command context

k_kunti
Champ in-the-making
Champ in-the-making
Dear Activiti team

I am using activiti 5.10 with SQLserver DB. My process has 4 async service task where each task call a stored procedure that takes 1 min to execute. I am getting the following exception when I start 100 instances using Jmeter. I have attached my process definition and engine config files , kindly help.

———————————————————————————————————————-
Process definition:

<?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: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="SpCall" name="SpCall">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="servicetask1" name="Service Task" activiti:async="true" activiti:class="com.sw.dbcall.DBCall"></serviceTask>
    <sequenceFlow id="flow2" name="" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <serviceTask id="servicetask2" name="Service Task" activiti:async="true" activiti:class="com.sw.dbcall.DBCall"></serviceTask>
    <sequenceFlow id="flow3" name="" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
    <serviceTask id="servicetask3" name="Service Task" activiti:async="true" activiti:class="com.sw.dbcall.DBCall"></serviceTask>
    <sequenceFlow id="flow4" name="" sourceRef="servicetask2" targetRef="servicetask3"></sequenceFlow>
    <serviceTask id="servicetask4" name="Service Task" activiti:async="true" activiti:class="com.sw.dbcall.DBCall"></serviceTask>
    <sequenceFlow id="flow5" name="" sourceRef="servicetask3" targetRef="servicetask4"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow6" name="" sourceRef="servicetask4" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_SpCall">
    <bpmndi:BPMNPlane bpmnElement="SpCall" id="BPMNPlane_SpCall">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="40" y="30"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55" width="105" x="90" y="90"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
        <omgdc:Bounds height="55" width="105" x="230" y="90"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">
        <omgdc:Bounds height="55" width="105" x="370" y="110"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask4" id="BPMNShape_servicetask4">
        <omgdc:Bounds height="55" width="105" x="380" y="200"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="540" y="210"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="57" y="65"></omgdi:waypoint>
        <omgdi:waypoint x="142" y="90"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="195" y="117"></omgdi:waypoint>
        <omgdi:waypoint x="230" y="117"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="335" y="117"></omgdi:waypoint>
        <omgdi:waypoint x="370" y="137"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="422" y="165"></omgdi:waypoint>
        <omgdi:waypoint x="432" y="200"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="485" y="227"></omgdi:waypoint>
        <omgdi:waypoint x="540" y="227"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

———————————————————————————————————————–
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

  <bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:db.properties" />
    <!– Allow other PropertyPlaceholderConfigurer to run as well –>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
  </bean>

 
    <!–<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="${jdbc.driver}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
       <property name="defaultAutoCommit" value="false" />
    </bean>
 
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url" value="jdbc:mysql://localhost:3306/activiti?autoReconnect=true" />
      <property name="username" value="root" />
      <property name="password" value="" />
       <property name="defaultAutoCommit" value="false" />
    </bean>   –>
   
    <!–   <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
               <property name="driverClass" value="com.mysql.jdbc.Driver" />
               <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?autoReconnect=true" />
               <property name="username" value="root"/>
               <property name="password" value=""/>
               <property name="idleConnectionTestPeriod" value="60"/>
               <property name="idleMaxAge" value="240"/>
               <property name="maxConnectionsPerPartition" value="30"/>
               <property name="minConnectionsPerPartition" value="10"/>
               <property name="partitionCount" value="5"/>
               <property name="acquireIncrement" value="5"/>
               <property name="statementsCacheSize" value="1000"/>
               <property name="releaseHelperThreads" value="3"/>
  </bean>–>
 
     
      <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
                 <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver"/>
                 <property name="jdbcUrl" value="jdbc:jtds:sqlserver://xxx:1433/activiti"/>
                 <property name="username" value="sa"/>
                 <property name="password" value="xxx"/>
                 <property name="idleConnectionTestPeriod" value="60"/>
                 <property name="idleMaxAge" value="240"/>
                 <property name="maxConnectionsPerPartition" value="50"/>
                 <property name="minConnectionsPerPartition" value="10"/>
                 <property name="partitionCount" value="5"/>
                 <property name="acquireIncrement" value="5"/>
                 <property name="statementsCacheSize" value="1000"/>
                 <property name="releaseHelperThreads" value="3"/>
  </bean>
 
               
         
 

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager"/>
    <property name="databaseSchemaUpdate" value="true"/>
    <property name="mailServerHost" value="localhost"/>
    <property name="mailServerPort" value="5025" />
    <property name="jobExecutorActivate" value="true"/>
   <property name="jobExecutor" ref="myJobExecutor"/>
  </bean>
 
<!–  <bean id="jobExecutor" class="org.activiti.engine.impl.jobexecutor.DefaultJobExecutor">
  <property name="corePoolSize" value="${activiti.jobExecutor.corePoolSize}"/>
  <property name="lockTimeInMillis" value="${activiti.jobExecutor.lockTimeInMillis}"/>
  <property name="maxJobsPerAcquisition" value="${activiti.jobExecutor.maxJobsPerAcquisition}"/>
  <property name="maxPoolSize" value="${activiti.jobExecutor.maxPoolSize}"/>
  <property name="queueSize" value="${activiti.jobExecutor.queueSize}"/>
  <property name="waitTimeInMillis" value="${activiti.jobExecutor.waitTimeInMillis}"/>
  </bean>–>
 
   
<bean id="myJobExecutor" class="org.activiti.engine.impl.jobexecutor.DefaultJobExecutor">
<property name="queueSize" value="30" />
<property name="corePoolSize" value="200" />
<property name="maxPoolSize" value="500" />
<property name="maxJobsPerAcquisition" value="300" />
<property name="waitTimeInMillis" value="1000" />
<property name="lockTimeInMillis" value="7200000"/>
</bean>

 


  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>

</beans>
———————————————————————————————————————–
Thank you
Best Regards
Krishnendu
=========================
SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.sql.SQLException: Transaction (Process
ID 181) was deadlocked on lock resources with another process and has been chos
en as the deadlock victim. Rerun the transaction.
### The error may involve org.activiti.engine.impl.persistence.entity.ExecutionE
ntity.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ?
### Cause: java.sql.SQLException: Transaction (Process ID 181) was deadlocked on
lock resources with another process and has been chosen as the deadlock victim.
Rerun the transaction.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(Exception
Factory.java:23)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSq
lSession.java:147)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSq
lSession.java:158)
        at org.activiti.engine.impl.db.DbSqlSession$DeleteById.execute(DbSqlSess
ion.java:146)
        at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.ja
va:483)
        at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:371)

        at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(Com
mandContext.java:157)
        at org.activiti.engine.impl.interceptor.CommandContext.close(CommandCont
ext.java:109)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execut
e(CommandContextInterceptor.java:49)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(Sp
ringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(T
ransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransa
ctionInterceptor.java:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterc
eptor.java:33)
        at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJ
obsRunnable.java:46)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:907)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Transaction (Process ID 181) was deadlocked on
lock resources with another process and has been chosen as the deadlock victim.
Rerun the transaction.
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.j
ava:368)
        at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
        at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
        at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.
java:584)
        at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java
:546)
        at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedS
tatement.java:558)
        at com.jolbox.bonecp.PreparedStatementHandle.execute(PreparedStatementHa
ndle.java:138)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(
PreparedStatementHandler.java:41)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(R
outingStatementHandler.java:66)
        at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.jav
a:45)
        at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108)

        at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.jav
a:75)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSq
lSession.java:145)
        … 15 more
        at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108)

        at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.jav
a:75)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSq
lSession.java:145)
        … 15 more
6 REPLIES 6

k_kunti
Champ in-the-making
Champ in-the-making
Dear Activiti Team

It would be a big help if you can point me to the packeges where core job executor logic is implemented and how async tasks uses the same.

Thank you
Best Regards
Krishnendu

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
It's in the JobExecutor class…

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
And next time, please use code tags around yor code… Reads much easier…

k_kunti
Champ in-the-making
Champ in-the-making
Hi All

Looks like this issue is coming up in SQL server DB when there are many concurrent process trying to update access the same table at the same time. In my case there were 200 concurrent process which where completing almost the same time.

Looks like when there are too many updates in SQL server DB row locks are converted to table level locks  resulting in this behavior. One solution is using some connection pooling solution which allows default isolation level as snapshot isolation level in SQL server. Unfortunately I could not find any open source connection pooling API using which I could achieve the same.

Thank you
Krishnendu

jbarrez
Star Contributor
Star Contributor
Looks like when there are too many updates in SQL server DB row locks are converted to table level locks resulting in this behavior.

Are you sure about, that sounds very, very strange for a database to do. Then again, it is of course a database from MS 😉
But if that is really the problem, then you need indeed some kind of throttling mechanism to avoid hitting the database to hard. Or I would there is a setting you can change in the configuration of the db.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Well, wikipedia even has some info on this: http://en.wikipedia.org/wiki/Lock_(database) and ofcourse the MS site: http://msdn.microsoft.com/en-us/library/ms184286(v=sql.105).aspx