用来定义子流程,当主流程遇到ProcessState就会停滞并生成子流程运行,子流程运行完毕重新回到主流程运行。主子流程的部署有点特殊(耗费了我3个小时才搞定,我开始认为只要在processdefinition.xml中定义好2个流程的关系,然后分别发布就好了,但是不行,一定要程序设置好两者的关系再发布)
主流程xml:
--------------------------------------------------
子流程xml:
-----------------------------------------------------
部署以及过程生成:
private static void Deploying_processstate(){
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
InputStream is = new FileInputStream("processes/yytest/processdefinition.xml");
processDefinition = ProcessDefinition.parseXmlInputStream(is);
InputStream subis = new FileInputStream("processes/subyytest/processdefinition.xml");
ProcessDefinition subprocessDefinition = ProcessDefinition.parseXmlInputStream(subis);
//建立关联关系
ProcessState processState = (ProcessState) processDefinition.getNode("initial_subyytest");
processState.setSubProcessDefinition(subprocessDefinition);
//一定要先部署子流程,不然hibernate会报错。
jbpmContext.deployProcessDefinition(subprocessDefinition);
jbpmContext.deployProcessDefinition(processDefinition);
} catch(FileNotFoundException e){
e.printStackTrace();
}finally {
jbpmContext.close();
}
}
private static void Starting_process(){
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
String processName="yytest";
processInstance =jbpmContext.newProcessInstance(processName);//只生成主流程就好了
}finally {
jbpmContext.close();
}
}
---------------------------------------------------
private static void run(){
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
long processInstanceId =1;
processInstance = jbpmContext.loadProcessInstance(processInstanceId);
Token token = processInstance.getRootToken();
System.out.println(token.getNode());
token.signal();
ProcessInstance subprocessInstance=token.getSubProcessInstance();
Token subtoken = subprocessInstance.getRootToken();
System.out.println(token.getNode());
System.out.println(subtoken.getNode());
subtoken.signal();
System.out.println(subtoken.getNode());
System.out.println(token.getNode());
jbpmContext.save(processInstance);
}finally {
jbpmContext.close();
}
}
-----------------------------------------------------
运行结果:
StartState(yyteststart)
ProcessState(initial_subyytest)
State(subyyteststate1)
EndState(subyytestend)
EndState(yytestend)
补充:
自循环的流程:
-----------------------------------------------------
关联指定version的子流程