[jboss-user] [jBPM] - LocalTaskService keep using one Entity Manager, Breaks when Database is Restarted

Thomas Setiabudi do-not-reply at jboss.com
Mon Aug 12 23:33:32 EDT 2013


Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"LocalTaskService keep using one Entity Manager, Breaks when Database is Restarted"

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

--------------------------------------------------------------
Hi,

This is similar post to  https://community.jboss.org/thread/231488?tstart=0 https://community.jboss.org/thread/231488?tstart=0
Only that it discuss about LocalTaskService here

I use JBPM5.4.Final, and Drools-Spring 5.4.Final in a Web Application.
I create Stateful Knowledge Session and LocalTaskService in the Spring config file, they are created once for the rest of the web application life.


Everything works fine, until the Database Server, MS SQL Server 2008, is restarted.
Which then break the Stateful Knowledge Session and LocalTaskService.


After looking at the LocalTaskService code here
 https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/task/service/local/LocalTaskService.java#L52-L55 https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/task/service/local/LocalTaskService.java#L52-L55
Local Task Service has TaskServiceSession and then TaskServiceSession has TaskPersistenceManager which contain an EntityManager.

The problem is this EntityManager is acquired from EntityManagerFactory just exactly once.
when the database connection is no longer valid (Because of Database Server restart), it will still use the same EntityManager which will of course throw exception.

My question is, is it a bug? or I use these LocalTaskService Wrongly?

Currently, to keep my application running, I create another class that implements TaskService, and have all the code just like LocalTaskService, the difference is I add a check before doing anything about the task.
This is a sample code:

public void addTask(Task task, ContentData content) {
                    checkEntityManagerFactory();
                    session.addTask(task, content);
          }
 


and the checkEntityManagerFactory() implementation:

public void checkEntityManagerFactory() {
                    if (session != null) {
                              try {
                                        Query query = session.getTaskPersistenceManager()
                                                            .createNewQuery("SELECT 1 FROM Task WHERE id = 0 ");
                                        query.getResultList();
                              } catch (Throwable e) {
                                        session = service.createSession();
                              }
 
 
                    } else {
                              session = service.createSession();
                    }
          }
 


execute simple select query, when that query throws exception, that means its time to get new EntityManager which in this case is create new TaskServiceSession.

Is it the correct way to do this?
Will this issue fixed in JBPM 6 ?

Any help is appreciated.


Regards,
Thomas Setiabudi
--------------------------------------------------------------

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130812/775990e2/attachment.html 


More information about the jboss-user mailing list