Activiti定时开始事件入门实例

开始定时事件(Start Event Timer)指在开始事件中指定定时器,在符合指定的时间时流程会自动启动。下面通过实例来学习该事件。

开始定时事件(Start Event Timer)指在开始事件中指定定时器,在符合指定的时间时流程会自动启动。下面通过实例来学习该事件。

图标:

定时开始事件图标

流程图:

定时开始流程

流程将在设定的时间点启动流程,然后流程进入“任务01”(需要调用complete方法),最后流程结束。

流程定义XML:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="https://activiti.org/bpmn" xmlns:bpmndi="https://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="https://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="https://www.omg.org/spec/DD/20100524/DI" typeLanguage="https://www.w3.org/2001/XMLSchema" expressionLanguage="https://www.w3.org/1999/XPath" targetNamespace="https://www.activiti.org/processdef">
  <process id="timerStartEventTest01" name="定时开始事件测试01" isExecutable="true">
    <startEvent id="start">
      <timerEventDefinition>
        <timeDate>2015-03-08T15:30:30</timeDate>
      </timerEventDefinition>
    </startEvent>
    <userTask id="task01" name="任务01"></userTask>
    <endEvent id="end"></endEvent>
	<sequenceFlow id="sid-B96A1813-6837-4845-8167-3ACA1A3B3D20" sourceRef="start" targetRef="task01"></sequenceFlow>
    <sequenceFlow id="sid-35F14E43-5255-4FCC-8962-209578CDE088" sourceRef="task01" targetRef="end"></sequenceFlow>
  </process>
  
  <bpmndi:BPMNDiagram id="BPMNDiagram_timerStartEventTest01">
    <bpmndi:BPMNPlane bpmnElement="timerStartEventTest01" id="BPMNPlane_timerStartEventTest01">
      <bpmndi:BPMNShape bpmnElement="task01" id="BPMNShape_task01">
        <omgdc:Bounds height="80.0" width="100.0" x="191.0" y="125.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
        <omgdc:Bounds height="28.0" width="28.0" x="336.0" y="151.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-35F14E43-5255-4FCC-8962-209578CDE088" id="BPMNEdge_sid-35F14E43-5255-4FCC-8962-209578CDE088">
        <omgdi:waypoint x="291.0" y="165.0"></omgdi:waypoint>
        <omgdi:waypoint x="336.0" y="165.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-B96A1813-6837-4845-8167-3ACA1A3B3D20" id="BPMNEdge_sid-B96A1813-6837-4845-8167-3ACA1A3B3D20">
        <omgdi:waypoint x="130.0" y="165.0"></omgdi:waypoint>
        <omgdi:waypoint x="191.0" y="165.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Activiti配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://www.springframework.org/schema/beans"
	xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="https://www.springframework.org/schema/beans
		https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
	
	<bean id="processEngineConfiguration"  
        class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUsername" value="root" />
        <property name="jdbcPassword" value="aaaaaa" />
        <property name="jobExecutorActivate" value="true" />
        <property name="databaseType" value="mysql"/>
        <property name="databaseSchemaUpdate" value="true" />
        <property name="history" value="full"/>
    </bean>
    
</beans>

Java客户端代码:

package com.bug315.event;

import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.task.TaskQuery;

/**
 * 定时开始事件测试
 * @author Administrator
 *
 */
public class TimerStartEventTest01 {

	public static void main(String[] args) throws InterruptedException {
		ProcessEngineImpl processEngine = (ProcessEngineImpl)ProcessEngines.getDefaultProcessEngine();
		
		processEngine.getProcessEngineConfiguration().getJobExecutor().start();
		
		RepositoryService repositoryService = processEngine.getRepositoryService();
		repositoryService.createDeployment().addClasspathResource("bpmn/timerStartEventTest01.bpmn20.xml").deploy();
		System.out.println("流程部署成功");

		// 暂停60秒
		Thread.sleep(1000 * 60);
		
		TaskService taskService = processEngine.getTaskService();
		TaskQuery taskQuery = taskService.createTaskQuery();
		System.out.println("task size = " + taskQuery.list().size());
		
		processEngine.getProcessEngineConfiguration().getJobExecutor().shutdown();
	}
	
}

注意事项:

1、使用定时器开始事件需要启动JobExecutor

人生就像赛跑,不在乎你是否第一个到达终点,而在乎你有没有跑完全程。
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
公众号