3 Replies Latest reply on May 9, 2013 2:56 PM by Demian Calcaprina

    Concurrency issue with LocalTaskService

    Jon Kranes Newbie

      I am running into a concurrency issue in my JBPM 5.4 application.  At first I thought it was related to thread safety of the StatefulKnowledgeSession issue discussed elsewhere, but I am able to recreate the issue without any session at all.


      I am using the Spring JtaTransactionManager with annotated transaction boundaries, with MySQL, and running on AS 7.1.1.


      The Spring configuration looks like this:



      {code:xml}<jee:jndi-lookup id="emf" jndi-name="persistence/myEmf"/>

      <bean id="sel" class="org.drools.SystemEventListenerFactory"

      factory-method="getSystemEventListener" />

      <bean id="jbpmTaskService" class="org.jbpm.task.service.TaskService"

      c:emf-ref="emf" c:systemEventListener-ref="sel" />

      <bean id="localTaskService" class="org.jbpm.task.service.local.LocalTaskService"

      c:taskService-ref="jbpmTaskService" />

      <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

      <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />

      <tx:annotation-driven transaction-manager="txManager" />{code}



      And the code triggering the problem is this:




      List<TaskSummary> tasks = localTaskService.getTasksAssignedAsPotentialOwner(assignee, "en-UK"));

             for (TaskSummary summary: tasks){

                   // ...

                      org.jbpm.task.Task t = localTaskService.getTask(summary.getId());

                   // ....





      Note that this code is annotated as @Transactional


      If I call this code from a single thread or inside a synchronized block I have no problems.  If I call it from multiple concurrent threads, I consistently trigger the error:


      java.lang.IllegalStateException: Trying to return an unknown connection2! org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@2a77a3c4


      The trigger seems to be the inner call to the localTaskService.  With just the outer call I have no problems. 


      Googling this error, it seems this was a common problem with older hibernate versions (2.x) but I did not find any references to people seeing it for hibernate 4.x.


      Any ideas?