[rules-users] Can Drools Flow Persistence Work without JTA

gs76pl gstasica at pacemetrics.com
Fri Apr 8 04:48:41 EDT 2011


as it turned out if one uses EntityManager configuration as I described in my
previous post and at the same time runs actions async by spawning new
threads then marking workItems as being completed can be a little tricky as
it's very easy to see "EntityManager has been closed" exception. The
solution to this problem is to use knowledgeSession that has been created
when the task was being created. 

i.e.
MyWorkItemHandler implements WorkItemHandler {

    //pass this session as a part of registering workitemhandler
   private StatefullKnowledgeSession knowledgeSession;

  public void executeWorkItem(final WorkItem workItem, final WorkItemManager
workItemManager){

      Thread t = new Thread(){
           @Override
            public void run()
	{
		action.execute(processContext, domainInstance);
                //don't use passes workItemManager as its entityManager has
been already closed (we're running tasks async)
		knowledgeSession.getWorkItemManager().completeWorkItem(workItem.getId(),
action.getResults());
	}
      };
	
        //start action async	
      t.start();		
  }
}

--
View this message in context: http://drools.46999.n3.nabble.com/Can-Drools-Flow-Persistence-Work-without-JTA-tp1647078p2794584.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list