Discussion:
[jboss-user] [jBPM] - Concurrency issue with LocalTaskService
Jon Kranes
2013-05-09 18:04:02 UTC
Permalink
Jon Kranes [https://community.jboss.org/people/jkranes] created the discussion

"Concurrency issue with LocalTaskService"

To view the discussion, visit: https://community.jboss.org/message/817047#817047

--------------------------------------------------------------
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:


<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" />


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! ***@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?

Thanks,

Jon
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817047#817047]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Demian Calcaprina
2013-05-09 18:14:08 UTC
Permalink
Demian Calcaprina [https://community.jboss.org/people/calca] created the discussion

"Re: Concurrency issue with LocalTaskService"

To view the discussion, visit: https://community.jboss.org/message/817049#817049

--------------------------------------------------------------
I had problems with LocalTaskService. I think the problem is that LocalTaskService is not thread safe.. I solved problems just creating a new LocalTaskService per requrest.

Thanks

Demian
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817049#817049]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Jon Kranes
2013-05-09 18:46:11 UTC
Permalink
Jon Kranes [https://community.jboss.org/people/jkranes] created the discussion

"Re: Concurrency issue with LocalTaskService"

To view the discussion, visit: https://community.jboss.org/message/817056#817056

--------------------------------------------------------------
Yes, creating a new LocalTaskService instance inside each method where I use it does seem to do the trick, so it does seem to be the source of the concurrency error.  At least based on some quick testing, I seem to be able to construct it using a singleton instance of org.jbpm.task.service.TaskService.  Next step is to optimize a bit by creating only one per request as you suggested.

Any other similar issues I should be looking out for?  I am still trying to figure out a good workaround for the StatefulKnowledgeSession thread safety issue.  I'm a bit concerned that all these thread safety issues, as the app I am working on is expected to eventually scale up fairly high.

Thanks,

Jon
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817056#817056]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Demian Calcaprina
2013-05-09 18:56:55 UTC
Permalink
Demian Calcaprina [https://community.jboss.org/people/calca] created the discussion

"Re: Concurrency issue with LocalTaskService"

To view the discussion, visit: https://community.jboss.org/message/817061#817061

--------------------------------------------------------------
Well, this was the last concurrency issue I had :) .
And I also know that the jBPM team is aware of the issue so it should be solevd in next release (probably jBPM6).

Thanks!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817061#817061]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...