Looping流程如下图所示:
如上图所示,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);
System.out.println(" i = " + i); kcontext.setVariable("i", i+1);
System.out.println("Loop completed");
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(); } }
Loop started i = 0 i = 1 i = 2 i = 3 i = 4 Loop completed