日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JBPM中 使用JobExecutor执行timer定义的job

發布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JBPM中 使用JobExecutor执行timer定义的job 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Job executor在jbpm.cfg.xml中是被缺省注釋的,所以只要去掉此行即可通過JobExecutor來定時觸發timer中的event-handler了?

Xml代碼

<jbpm-configuration><import resource="jbpm.default.cfg.xml" /><import resource="jbpm.businesscalendar.cfg.xml" /><import resource="jbpm.tx.hibernate.cfg.xml" /><import resource="jbpm.jpdl.cfg.xml" /><import resource="jbpm.bpmn.cfg.xml" /><import resource="jbpm.identity.cfg.xml" /><!-- Job executor is excluded for running the example test cases. --><!-- To enable timers and messages in production use, this should be included. --><import resource="jbpm.jobexecutor.cfg.xml" /> </jbpm-configuration>
測試代碼

/*** @author hzhlu*/ public class CopyOfTimerRepeatTest extends JbpmTestCase {String deploymentId;protected void setUp() throws Exception {super.setUp();deploymentId = repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/examples/timer/repeat/process.jpdl.xml").deploy();}protected void tearDown() throws Exception {repositoryService.deleteDeploymentCascade(deploymentId);super.tearDown();}public void testTimerRepeat() {ProcessInstance processInstance = executionService.startProcessInstanceByKey("TimerRepeat");// 查詢進入狀態后是否已經建立起timer jobJob job = managementService.createJobQuery().processInstanceId(processInstance.getId()).uniqueResult();System.out.println("job info:" + job.getDueDate() + " " + job.toString());assertNull(executionService.getVariable(processInstance.getId(), "escalations"));String msg;for (int i = 0; i < 10; i++) {long difference = job.getDueDate().getTime() - System.currentTimeMillis();msg = "Job觸發倒計時: " + difference + " check escalations:"+ executionService.getVariable(processInstance.getId(), "escalations");System.out.println(">>> " + msg);// 延時1秒try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}} }

JPDL 定義文件,3秒鐘后觸發,然后每隔5秒再觸發事件?

XML代碼

<?xml version="1.0" encoding="UTF-8"?><process name="TimerRepeat" xmlns="http://jbpm.org/4.4/jpdl"><start g="19,50,48,48"><transition to="guardedWait" /></start><state name="guardedWait" g="98,46,127,52"><on event="timeout1"><timer duedate="3 seconds" repeat="5 seconds" /><event-listener class="org.jbpm.examples.timer.repeat.Escalate" /></on><transition name="go on" to="next step" g="-16,-17"/></state><state name="next step" g="283,46,83,53"/></process>

事件處理程序?

Java代碼?

public class Escalate implements EventListener {private static final long serialVersionUID = 1L;public void notify(EventListenerExecution execution) {System.out.println("Escalate.notify()");Integer escalations = (Integer) execution.getVariable("escalations");if (escalations == null) {execution.setVariable("escalations", 1);} else {execution.setVariable("escalations", escalations + 1);}} }

執行結果?

job info:2010-07-27 14:55:43.0 timer[9|2010-07-27 14:55:43|timeout1]?

>>> Job觸發倒計時: 2907 check escalations:null?

>>> Job觸發倒計時: 1907 check escalations:null?

>>> Job觸發倒計時: 891 check escalations:null?

Escalate.notify()?

>>> Job觸發倒計時: -109 check escalations:1?

>>> Job觸發倒計時: -1125 check escalations:1?

>>> Job觸發倒計時: -2125 check escalations:1?

>>> Job觸發倒計時: -3125 check escalations:1?

>>> Job觸發倒計時: -4140 check escalations:1?

Escalate.notify()?

>>> Job觸發倒計時: -5140 check escalations:2?

>>> Job觸發倒計時: -6140 check escalations:2?




總結

以上是生活随笔為你收集整理的JBPM中 使用JobExecutor执行timer定义的job的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。