JBoss 系列三十四:jBPM5示例之 Looping

Looping流程如下图所示:

JBoss 系列三十四:jBPM5示例之 Looping_第1张图片

如上图所示,Looping流程有三个Script Task节点,Init, Loop, Done。

Init节点是Loop开始节点,它初始化两个变量count和i,分别赋值5和0,如下

System.out.println("Loop started");
kcontext.setVariable("count", 5);
kcontext.setVariable("i", 0);

Loop节点每次输出变量i的值,并给变量i加1,当变量i小于count的值5时,执行循环,如下

System.out.println("  i = " + i);
kcontext.setVariable("i", i+1);

Done节点输出Looping流程结束字符串,如下

System.out.println("Loop completed");

  • Looping流程运行代码:https://github.com/kylinsoong/.../looping/LoopingStart.java
  • Looping流程:https://github.com/kylinsoong/.../quickstarts/looping.bpmn
运行 org.jbpm.quickstarts.looping.LoopingStart可运行Looping流程, LoopingStart代码如下

package org.jbpm.quickstarts.looping;

import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.quickstarts.QuickStartBase;

public class LoopingStart extends QuickStartBase{

	public void test() {
		StatefulKnowledgeSession ksession = createKnowledgeSession("quickstarts/looping.bpmn");
		ksession.startProcess("org.jbpm.quickstarts.looping");
	}
	
	public static void main(String[] args) {
		new LoopingStart().test();
	}

}

运行 Looping流程输出结果如下:

Loop started
  i = 0
  i = 1
  i = 2
  i = 3
  i = 4
Loop completed


你可能感兴趣的:(jboss,jbpm,实例,BPM,JBPM5)