当一个流程的业务逻辑非常复杂的时候,可以考虑使用子流程。
子流程和主流程是相对独立的,关于process state节点的wait状态,也是根据子流程决定的。
使用子流程要注意:
1、要先部署子流程,然后再部署主流程,否则,主流成执行的时候会报找不到子流程的异常
2、主流程的process state节点要映射变量,作为主流程和子流程的调用参数
3、直接查看jbpm_Token或者jbpm_log无法找到流程间的关系,需要查看jbpm_processinstance表,才能找到父流程,因为Token在离开process state的时候就会删除subprocessid,直接看jbpm_log也无法看出两个token之间的关系。
参考代码如下:
子流程的定义如下:
子流程和主流程是相对独立的,关于process state节点的wait状态,也是根据子流程决定的。
使用子流程要注意:
1、要先部署子流程,然后再部署主流程,否则,主流成执行的时候会报找不到子流程的异常
2、主流程的process state节点要映射变量,作为主流程和子流程的调用参数
3、直接查看jbpm_Token或者jbpm_log无法找到流程间的关系,需要查看jbpm_processinstance表,才能找到父流程,因为Token在离开process state的时候就会删除subprocessid,直接看jbpm_log也无法看出两个token之间的关系。
参考代码如下:
1
<?xml version="1.0" encoding="UTF-8"?>
2![]()
3
<process-definition
4
xmlns="urn:jbpm.org:jpdl-3.2" name="main">
5![]()
6![]()
7![]()
8
<start-state name="start-state1">
9
<task name="begin_task"></task>
10
<transition to="process-state1"></transition>
11
<event type="node-leave">
12
<script name="begin_s">
13
executionContext.setVariable("a",new Integer(10));
14
System.out.println("begin_s");
15
</script>
16
</event>
17
</start-state>
18![]()
19![]()
20
<process-state name="process-state1">
21
<sub-process name="sub"></sub-process>
22
<variable access="read,write" name="a" mapped-name="a"></variable>
23
<transition to="node1"></transition>
24
</process-state>
25![]()
26
<node name="node1">
27
<event type="node-enter">
28
<script name="no_s">
29
30
System.out.println(executionContext.getVariable("a"));
31
32
</script>
33
</event>
34
<transition to="end-state1"></transition>
35
</node>
36![]()
37![]()
38
<end-state name="end-state1"></end-state>
39![]()
40![]()
41
</process-definition>
<?xml version="1.0" encoding="UTF-8"?>2

3
<process-definition4
xmlns="urn:jbpm.org:jpdl-3.2" name="main">5

6

7

8
<start-state name="start-state1">9
<task name="begin_task"></task>10
<transition to="process-state1"></transition>11
<event type="node-leave">12
<script name="begin_s">13
executionContext.setVariable("a",new Integer(10));14
System.out.println("begin_s");15
</script>16
</event>17
</start-state>18

19

20
<process-state name="process-state1">21
<sub-process name="sub"></sub-process>22
<variable access="read,write" name="a" mapped-name="a"></variable>23
<transition to="node1"></transition>24
</process-state>25

26
<node name="node1">27
<event type="node-enter">28
<script name="no_s">29
30
System.out.println(executionContext.getVariable("a"));31
32
</script>33
</event>34
<transition to="end-state1"></transition>35
</node>36

37

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

40

41
</process-definition>子流程的定义如下:
1
<?xml version="1.0" encoding="UTF-8"?>
2![]()
3
<process-definition
4
xmlns="urn:jbpm.org:jpdl-3.2" name="sub">
5![]()
6![]()
7![]()
8
<start-state name="start-state1">
9
<transition to="sub_task-node1"></transition>
10
</start-state>
11![]()
12![]()
13
<task-node name="sub_task-node1">
14
<event type="node-enter">
15
<script name="s1">
16
Integer a=(Integer)executionContext.getVariable("a");
17
System.out.println(a);
18
a=new Integer(200);
19
executionContext.setVariable("a",a);
20![]()
21
</script>
22
</event>
23
<transition to="end-state1"></transition>
24
</task-node>
25![]()
26![]()
27
<end-state name="end-state1"></end-state>
28![]()
29![]()
30
</process-definition>
<?xml version="1.0" encoding="UTF-8"?>2

3
<process-definition4
xmlns="urn:jbpm.org:jpdl-3.2" name="sub">5

6

7

8
<start-state name="start-state1">9
<transition to="sub_task-node1"></transition>10
</start-state>11

12

13
<task-node name="sub_task-node1">14
<event type="node-enter">15
<script name="s1">16
Integer a=(Integer)executionContext.getVariable("a");17
System.out.println(a);18
a=new Integer(200);19
executionContext.setVariable("a",a);20

21
</script>22
</event>23
<transition to="end-state1"></transition>24
</task-node>25

26

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

29

30
</process-definition>
浙公网安备 33010602011771号