论坛首页 Java企业应用论坛

jbpm的调度应用3-end

浏览 10482 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-12-08  

timer如果在task中,有一个属性cancel-event,可以指定那些事件可以终止timer的执行,默认是task-end,也可以指定多个事件如:<timer duedate="2 business minutes" cancel-event="task-start, task-assign, task-end"></timer>。

下面举一个默认为task-end的例子:

xml 代码
  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <process-definition xmlns="" name="yytest">  
  3.    <start-state name="start">  
  4.       <transition name="" to="a">transition>  
  5.    start-state>  
  6.    <task-node name='a'>  
  7.         <task name='reminder'>  
  8.             <timer name='reminder' duedate='5 seconds' repeat='3 seconds'  
  9.                      >  
  10.                 <script>System.out.println(new Date()+"----node enter:send mail to operator.");script>  
  11.             timer>  
  12.         task>  
  13.         <transition name="" to="end">transition>  
  14.     task-node>  
  15.    <end-state name="end">end-state>       
  16. process-definition>  

 

java 代码
  1. package com.jeffentest;   
  2.   
  3. import org.jbpm.*;   
  4. import org.jbpm.graph.def.ProcessDefinition;   
  5. import org.jbpm.graph.exe.*;   
  6. import org.jbpm.scheduler.impl.Scheduler;   
  7.   
  8.   
  9. public class Jeffentest {   
  10.     static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();   
  11.     static ProcessDefinition processDefinition = null;   
  12.     static ProcessInstance processInstance = null;   
  13.     static Scheduler scheduler = null;   
  14.   
  15.     public static void initSchedular() {//设置Schedular的属性   
  16.         scheduler = new Scheduler();   
  17.         int interval = 5000;   
  18.         scheduler.setInterval(interval);   
  19.         int historyMaxSize = 0;   
  20.         scheduler.setHistoryMaxSize(historyMaxSize);   
  21.         scheduler.start();   
  22.     }   
  23.          
  24.     public static void destroy() {//这个例子没用到   
  25.         scheduler.stop();   
  26.     }   
  27.     static class MySchedularThread extends Thread{//实际业务处理线程   
  28.         public void run(){   
  29.             JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();   
  30.             try {   
  31.                 long processInstanceId =1;   
  32.                    processInstance = jbpmContext.loadProcessInstance(processInstanceId);   
  33.                    Token token = processInstance.getRootToken();   
  34.                    System.out.println(token.getNode());   
  35.                    //一定要运行到有timer生成,触发   
  36.                    token.signal();   
  37.                    System.out.println(token.getNode());   
  38.                    jbpmContext.save(processInstance);   
  39.                    //jbpm_timer表里有一条数据。timer将永久运行下去,直到taskinstance.end()   
  40.                    Thread.sleep(30*1000);//为模拟效果,此线程停止30秒   
  41.                    jbpmContext.getTaskInstance(1).start();   
  42.                    jbpmContext.getTaskInstance(1).end();//如果,屏蔽掉该句试试   
  43.                    System.out.println(token.getNode());       
  44.                    jbpmContext.save(processInstance);     
  45.             }catch(Exception e){   
  46.                 e.printStackTrace();   
  47.             }finally {   
  48.                   jbpmContext.close();   
  49.             }   
  50.         }   
  51.     }   
  52.            
  53.     public static void main(String[] args) {   
  54.         initSchedular ();   
  55.         MySchedularThread mst=new MySchedularThread();   
  56.         mst.start();   
  57.     }   
  58. }   

运行结果如下:

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 代码
  1. <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)

好了调度的应用就说这么多吧。没人了,赶紧去吃饭。

   发表时间:2007-01-15  
我的怎么 不再jbpmContext.save(processInstance);后面加上
jbpmContext.close()数据库中就没有记录
调度就不执行
0 请登录后投票
   发表时间:2007-06-27  
这是3.1的,jBPM 3.2中没有Scheduler
0 请登录后投票
   发表时间:2007-07-19  
我用jbpmContext.deployProcessDefinition(processDefinition);发布流程后,jbpm_timer中没有我在流程中定义的timer,是什么原因引起的?
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics