- jeffen2006
- 等级:
- 性别:
- 文章: 36
- 积分: 167
- 来自: 深圳
|
timer如果在task中,有一个属性cancel-event,可以指定那些事件可以终止timer的执行,默认是task-end,也可以指定多个事件如:<timer duedate="2 business minutes" cancel-event="task-start, task-assign, task-end"></timer>。
下面举一个默认为task-end的例子:
xml 代码
- <!---->xml version="1.0" encoding="UTF-8"?>
- <process-definition xmlns="" name="yytest">
- <start-state name="start">
- <transition name="" to="a">transition>
- start-state>
- <task-node name='a'>
- <task name='reminder'>
- <timer name='reminder' duedate='5 seconds' repeat='3 seconds'
- >
- <script>System.out.println(new Date()+"----node enter:send mail to operator.");script>
- timer>
- task>
- <transition name="" to="end">transition>
- task-node>
- <end-state name="end">end-state>
- process-definition>
java 代码
- package com.jeffentest;
-
- import org.jbpm.*;
- import org.jbpm.graph.def.ProcessDefinition;
- import org.jbpm.graph.exe.*;
- import org.jbpm.scheduler.impl.Scheduler;
-
-
- public class Jeffentest {
- static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
- static ProcessDefinition processDefinition = null;
- static ProcessInstance processInstance = null;
- static Scheduler scheduler = null;
-
- public static void initSchedular() {
- scheduler = new Scheduler();
- int interval = 5000;
- scheduler.setInterval(interval);
- int historyMaxSize = 0;
- scheduler.setHistoryMaxSize(historyMaxSize);
- scheduler.start();
- }
-
- public static void destroy() {
- scheduler.stop();
- }
- static class MySchedularThread extends Thread{
- public void run(){
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
- long processInstanceId =1;
- processInstance = jbpmContext.loadProcessInstance(processInstanceId);
- Token token = processInstance.getRootToken();
- System.out.println(token.getNode());
-
- token.signal();
- System.out.println(token.getNode());
- jbpmContext.save(processInstance);
-
- Thread.sleep(30*1000);
- jbpmContext.getTaskInstance(1).start();
- jbpmContext.getTaskInstance(1).end();
- System.out.println(token.getNode());
- jbpmContext.save(processInstance);
- }catch(Exception e){
- e.printStackTrace();
- }finally {
- jbpmContext.close();
- }
- }
- }
-
- public static void main(String[] args) {
- initSchedular ();
- MySchedularThread mst=new MySchedularThread();
- mst.start();
- }
- }
运行结果如下:
StartState(start)
TaskNode(a)
Fri Dec 08 11:22:17 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:22:22 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:22:27 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:22:32 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:22:37 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:22:42 CST 2006----node enter:send mail to operator.
EndState(end)
如果想要task启动的时候,timer就终止,可以这样配置
xml 代码
- <timer name='reminder' duedate='5 seconds' repeat='3 seconds' cancel-event='task-start'>
结果如下:
StartState(start)
TaskNode(a)
Fri Dec 08 11:35:59 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:36:04 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:36:09 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:36:14 CST 2006----node enter:send mail to operator.
Fri Dec 08 11:36:19 CST 2006----node enter:send mail to operator.
TaskNode(a)
好了调度的应用就说这么多吧。没人了,赶紧去吃饭。
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- liu_hua1984cf
- 等级: 初级会员
- 文章: 7
- 积分: 32
- 来自: ...
|
我的怎么 不再jbpmContext.save(processInstance);后面加上
jbpmContext.close()数据库中就没有记录
调度就不执行
|
返回顶楼 |
|
|
- hantsy
- 等级:
- 性别:
- 文章: 672
- 积分: 136
- 来自: 广州
|
这是3.1的,jBPM 3.2中没有Scheduler
|
返回顶楼 |
|
|
- delphidoc
- 等级: 初级会员
- 性别:
- 文章: 1
- 积分: 30
- 来自: 北京
|
我用jbpmContext.deployProcessDefinition(processDefinition);发布流程后,jbpm_timer中没有我在流程中定义的timer,是什么原因引起的?
|
返回顶楼 |
|
|