Activiti5 定时任务 定时边界事件

activiti定时边界事件

Java代码   收藏代码
  1. "1.0" encoding="UTF-8"?>  
  2. "http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">  
  3.   "myProcess" name="My process" isExecutable="true">  
  4.     "startevent1" name="Start">  
  5.     "usertask1" name="1" activiti:assignee="lingling">  
  6.     "flow1" sourceRef="startevent1" targetRef="usertask1">  
  7.     "boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="false">  
  8.         
  9.         ${timeDuration}  
  10.         
  11.       
  12.     "usertask2" name="2" activiti:assignee="dongxh">  
  13.     "flow4" sourceRef="usertask1" targetRef="usertask2">  
  14.     "endevent1" name="End">  
  15.     "flow5" sourceRef="usertask2" targetRef="endevent1">  
  16.     "boundarytimer2" name="Timer" attachedToRef="usertask2" cancelActivity="false">  
  17.         
  18.         ${timeDuration}  
  19.         
  20.       
  21.     "servicetask1" name="Service Task" activiti:delegateExpression="${swTimeOutProcessorListener}">  
  22.     "flow6" sourceRef="boundarytimer1" targetRef="servicetask1">  
  23.     "flow7" sourceRef="boundarytimer2" targetRef="servicetask1">  
  24.     
  25.   "BPMNDiagram_myProcess">  
  26.     "myProcess" id="BPMNPlane_myProcess">  
  27.       "startevent1" id="BPMNShape_startevent1">  
  28.         "35.0" width="35.0" x="60.0" y="80.0">  
  29.         
  30.       "endevent1" id="BPMNShape_endevent1">  
  31.         "35.0" width="35.0" x="660.0" y="80.0">  
  32.         
  33.       "usertask1" id="BPMNShape_usertask1">  
  34.         "78.0" width="105.0" x="202.0" y="59.0">  
  35.         
  36.       "boundarytimer1" id="BPMNShape_boundarytimer1">  
  37.         "30.0" width="30.0" x="230.0" y="130.0">  
  38.         
  39.       "usertask2" id="BPMNShape_usertask2">  
  40.         "55.0" width="105.0" x="411.0" y="70.0">  
  41.         
  42.       "boundarytimer2" id="BPMNShape_boundarytimer2">  
  43.         "30.0" width="30.0" x="449.0" y="114.0">  
  44.         
  45.       "servicetask1" id="BPMNShape_servicetask1">  
  46.         "55.0" width="105.0" x="317.0" y="240.0">  
  47.         
  48.       "flow1" id="BPMNEdge_flow1">  
  49.         "95.0" y="97.0">  
  50.         "202.0" y="98.0">  
  51.         
  52.       "flow4" id="BPMNEdge_flow4">  
  53.         "307.0" y="98.0">  
  54.         "411.0" y="97.0">  
  55.         
  56.       "flow5" id="BPMNEdge_flow5">  
  57.         "516.0" y="97.0">  
  58.         "660.0" y="97.0">  
  59.         
  60.       "flow6" id="BPMNEdge_flow6">  
  61.         "245.0" y="160.0">  
  62.         "369.0" y="240.0">  
  63.         
  64.       "flow7" id="BPMNEdge_flow7">  
  65.         "464.0" y="144.0">  
  66.         "369.0" y="240.0">  
  67.         
  68.       
  69.     
  70.   

 流程图:

 
Activiti5 定时任务 定时边界事件_第1张图片
 

 

 

serviceTask处理:

 

Java代码   收藏代码
  1. @Component  
  2. public class SwTimeOutProcessorListener implements JavaDelegate {  
  3.   
  4.     @Autowired  
  5.     private TimeOutManagerService timeOutManagerService;  
  6.     @Autowired  
  7.     private TaskService taskService;  
  8.       
  9.     @Override  
  10.     public void execute(DelegateExecution execution) throws Exception {  
  11.         //获得事务id  
  12.         String businessKey = execution.getProcessBusinessKey();  
  13.         Task task = taskService.createTaskQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();  
  14.         String assignee =task.getAssignee();  
  15.           
  16.         System.out.println(assignee);  
  17.           
  18.         //插入超时记录  
  19.         //timeOutManagerService.addTimeOut(Integer.valueOf(assignee), Integer.valueOf(businessKey));  
  20.           
  21.           
  22.     }  
  23.   
  24. }  

 

 

定时边间事件:cancelActivity 说明:

cancelActivity属性:true时,当timer触发时,当前的activity被中断(流程结束);

                                false时,当timer触发时,不会被中断(流程原点,流程不会结束),

 

当执行循环定时器时,虽然cancelActivity=true,但是该acitivity还是会持续生成

 

cancelActivity默认为true中断事件(结束流程)

cancelActivity为false非中断事件(还停留在原地,流程不结束)

中断和非中断的事件还是有区别的。默认是中断事件。

非中断事件的情况,不会中断原始环节,那个环节还停留在原地。 对应的,会创建一个新分支,并沿着事件的流向继续执行。 

 

例子:


Activiti5 定时任务 定时边界事件_第2张图片
 

你可能感兴趣的:(activiti)