fork、join

一、processdefinition.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="forkjointest">


<start-state name="start-state1">
<transition to="fork1"></transition>
</start-state>


<fork name="fork1">
<script>
<variable name="transNames" access="write"></variable>
<expression>
transNames=new ArrayList();
if(param>100){
    transNames.add("to node1");
    transNames.add("to node2");
}else{
transNames.add("to node3");
transNames.add("to node4");
}
</expression>
</script>
<transition to="node1" name="to node1"></transition>
<transition to="node2" name="to node2"></transition>
<transition to="node3" name="to node3"></transition>
<transition to="node4" name="to node4"></transition>
</fork>



<node name="node1">
<event type="node-enter">
<script >
print(&quot;经过node1…………………………&quot;);
</script>
</event>
<transition to="join1"></transition>
</node>

<node name="node2">
<event type="node-enter">
<script >
print(&quot;经过node2…………………………&quot;);
</script>
<script></script>
<script></script>
<script></script>
</event>
<transition to="join1"></transition>
</node>

<node name="node3">
<event type="node-enter">
<script>
print(&quot;经过node3…………………………&quot;);
</script>
</event>
<transition to="join1"></transition>
</node>

<node name="node4">
<event type="node-enter">
<script>
print(&quot;经过node4…………………………&quot;);
</script>
</event>
<transition to="join1"></transition>
</node>
<join name="join1">
<transition to="end-state1"></transition>
</join>

<end-state name="end-state1"></end-state>


</process-definition>
二、流程发布以后的测试类
package cn.oa.jbpm.test;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;

public class ForkJoinTest {
//fork 和join节点
public static void main(String[] args) {
JbpmContext jbpmContext=JbpmConfiguration.getInstance().createJbpmContext();
try {
ProcessDefinition processDefinition=jbpmContext.getGraphSession().findLatestProcessDefinition("forkjointest");
ProcessInstance pi=processDefinition.createProcessInstance();
pi.getContextInstance().setVariable("param", 55);
Token token=pi.getRootToken();
token.signal();
System.out.println("*************"+token.getNode().getName());

} finally {
jbpmContext.close();
}
}
}

你可能感兴趣的:(JOIN)