JBoss series forty-one: jBPM5 example of Timer Event

In the BPM process, often need to pause before executing a task or after a period of time, jBPM5 use Timer Event this is done, as is DelayTimerEvent process:


As shown, DelayTimerEvent process there are three nodes, Before Timer, Timer, After Timer. Before Timer is Script Task nodes, Java code, operating state of the node performs the following:

timeBeforeTimer = System.currentTimeMillis();
System.out.println("Before Timer - " + new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss").format( new Date((Long)timeBeforeTimer)));
kcontext.setVariable("timeBeforeTimer", timeBeforeTimer);

Timer Event Timer is the node that is set Delay Timer is 5 seconds, i.e., when the continued operation of the process to the node pauses for five seconds.
After Timer is Script Task nodes, Java code, operating state of the node performs the following:

Long timeAfter = System.currentTimeMillis();
System.out.println("After  Timer - " +  new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss").format( new Date(timeAfter)));
timerExecutionTime = timeAfter - (Long) timeBeforeTimer;
kcontext.setVariable("timerExecutionTime", timerExecutionTime);

Run org.jbpm.quickstarts.event.DelayTimerEventStart runs DelayTimerEvent process, DelayTimerEventStart code is as follows:

package org.jbpm.quickstarts.event;

import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkflowProcessInstance;
import org.jbpm.quickstarts.QuickStartBase;

public class DelayTimerEventStart extends QuickStartBase {

	public static void main(String[] args) {
		new DelayTimerEventStart().test();
	}

	@SuppressWarnings("static-access")
	public void test() {
		StatefulKnowledgeSession ksession = createKnowledgeSession("quickstarts/delayTimerEventProcess.bpmn");
		ProcessInstance process = ksession.startProcess("org.jbpm.quickstarts.delaytimereventprocess");
		try {
			Thread.currentThread().sleep(6000);
		} catch (InterruptedException e) {	
		}
		Long timerExecutionTime = (Long) ((WorkflowProcessInstance)process).getVariable("timerExecutionTime");
		System.out.println("The Process Execute Time: " + timerExecutionTime);
		ksession.dispose();
	}

}

DelayTimerEvent output operation process is as follows:

Before Timer - 02013-20-30 03:20:29
After  Timer - 02013-20-30 03:20:34
The Process Execute Time: 5006

As results of the process execution time is 5006 milliseconds, i.e. due Timer Delay lead set node 5 seconds.

Reproduced in: https: //my.oschina.net/iwuyang/blog/197146

Guess you like

Origin blog.csdn.net/weixin_33699914/article/details/91897312