[jboss-user] [jBPM] New message: "Re: How to terminate a forked process"

Jas Lam do-not-reply at jboss.com
Fri Jan 8 10:42:51 EST 2010


User development,

A new message was posted in the thread "How to terminate a forked process":

http://community.jboss.org/message/519000#519000

Author  : Jas Lam
Profile : http://community.jboss.org/people/lamj1

Message:
--------------------------------------------------------------
In fact, my code is somewhat irrelevant. It is more like how to terminate a forked process while it is still active? without causing exception and ensure the database entities are cleaned up gracefully.
 
 
Junit code:  
public void testForking()
  {
 ProcessInstance processInstance = workflowManager.startProcess("ForkSubProcess");
 String pid = processInstance.getId();
 
 //sleep to allow fork to create task before querying it
 try {Thread.sleep(2000);} catch(Exception e){}
 
 //verify that there are two outstanding tasks assign to testUser 
 List<Task> taskList = taskService.findPersonalTasks("testUser");
 assertEquals(2, taskList.size());
 
//attempt to ends all processes, while they are still active
 workflowManager.endAll();
}
 
 public void endAll()
 {
ProcessInstanceQuery query = executionService.createProcessInstanceQuery();
 List<ProcessInstance> listPI = query.list();
 
 for(ProcessInstance processInstance : listPI)
 {
 //using execution service to end 
 //1. cause a child record found error - if this is the parent process
 //2. cause a null pointer exception - if this is the forked process
 // For the second case, I traced the code and found out that endProcessInstance method
 // query for the processInstanceid with a where clause parents == null
 //   <query name="findProcessInstanceById">
 //     <![CDATA[
 //      select processInstance
 //      from org.jbpm.pvm.internal.model.ExecutionImpl as processInstance
 //      where processInstance.id = :processInstanceId
 //        and processInstance.parent is null
 //        and processInstance.state != 'suspended'
 //     ]]>
 //   </query>
 executionService.endProcessInstance(processInstance.getId(), "active");
 
 //OR
 //i also tried this - unit test quit after this. Nothing was done
 ((ExecutionImpl) processInstance).end();
 }
}

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/519000#519000




More information about the jboss-user mailing list