1. 程式人生 > >Activiti定時任務示例

Activiti定時任務示例

工作流其實做的事情還是很多的, 
這不,這周公司經理叫我在前段時間的基礎上,把專案中的一個客戶回訪計劃的提醒功能也加到工作流當中,對於沒有接觸過定時任務的我來說,又有的一番研究了。 
在 咖啡兔 http://weibo.com/kafeituzi 的提醒下,使用了邊界定時事件 + Job的方式成功實現了,任務定時啟動,任務超時過期處理的功能,必須得感謝兔子,感謝他對Activiti在國內的普及所作出的努力。也希望Activiti的路越走越遠,現在5.11版本還是和以前老版本有了很多的變化了,好用,簡單實用的API,有了native query,也方便自己擴充套件。 
好了,廢話不多說,開始分析例項: 
1.開啟JOB引擎,在activiti配置檔案中: 
Java程式碼  
收藏程式碼
  1. <property name="jobExecutorActivate" value="true" />  

這個必須開啟,如果沒有開啟的話,定時任務是啟動不了的。呵呵, 
其實這個功能開啟過後,在後臺的實現是這樣餓,它會定時的查詢act_ru_job這一張表,看見我們的某一條記錄的時間要求達到了,就會執行這一個JOB。是不是就明白了?如果是web專案,你開啟LOG功能,在控制檯是可以看見日誌輸出的,其實就是這個JOB引擎在工作。 
2.下面就是流程圖設計。 

Xml程式碼  收藏程式碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <
    definitions xmlns="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.   <process id="notify" name="任務計劃" isExecutable="true">  
  4.     <userTask id="usertask1" name="任務等待"></userTask>  
  5.     <endEvent id="endevent1" name="End"></endEvent>  
  6.     <startEvent id="startevent1" name="Start"></startEvent>  
  7.     <sequenceFlow id="flow5" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>  
  8.     <boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="true">  
  9.       <timerEventDefinition>  
  10.         <timeDate>${qishi}</timeDate>  
  11.       </timerEventDefinition>  
  12.     </boundaryEvent>  
  13.     <userTask id="usertask2" name="任務提醒" activiti:candidateUsers="123">  
  14.       <extensionElements>  
  15.         <activiti:taskListener event="create" delegateExpression="${notifyHandler}"></activiti:taskListener>  
  16.       </extensionElements>  
  17.     </userTask>  
  18.     <sequenceFlow id="flow6" sourceRef="boundarytimer1" targetRef="usertask2"></sequenceFlow>  
  19.     <serviceTask id="servicetask3" name="任務處理" activiti:expression="${myHandler}"></serviceTask>  
  20.     <sequenceFlow id="flow7" sourceRef="usertask2" targetRef="servicetask3"></sequenceFlow>  
  21.     <sequenceFlow id="flow8" sourceRef="servicetask3" targetRef="endevent1"></sequenceFlow>  
  22.     <boundaryEvent id="boundarytimer2" name="Timer" attachedToRef="usertask2" cancelActivity="true">  
  23.       <timerEventDefinition>  
  24.         <timeDate>${jieshu}</timeDate>  
  25.       </timerEventDefinition>  
  26.     </boundaryEvent>  
  27.     <serviceTask id="servicetask4" name="任務過期" activiti:delegateExpression="${myHandler2}"></serviceTask>  
  28.     <sequenceFlow id="flow9" sourceRef="boundarytimer2" targetRef="servicetask4"></sequenceFlow>  
  29.     <sequenceFlow id="flow10" sourceRef="servicetask4" targetRef="endevent1"></sequenceFlow>  
  30.   </process>  
  31.   <bpmndi:BPMNDiagram id="BPMNDiagram_notify">  
  32.     <bpmndi:BPMNPlane bpmnElement="notify" id="BPMNPlane_notify">  
  33.       <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">  
  34.         <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="110.0"></omgdc:Bounds>  
  35.       </bpmndi:BPMNShape>  
  36.       <bpmndi:BPMNShape bpmnElement="boundarytimer1" id="BPMNShape_boundarytimer1">  
  37.         <omgdc:Bounds height="30.0" width="30.0" x="271.0" y="124.0"></omgdc:Bounds>  
  38.       </bpmndi:BPMNShape>  
  39.       <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">  
  40.         <omgdc:Bounds height="35.0" width="35.0" x="670.0" y="120.0"></omgdc:Bounds>  
  41.       </bpmndi:BPMNShape>  
  42.       <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">  
  43.         <omgdc:Bounds height="35.0" width="35.0" x="70.0" y="120.0"></omgdc:Bounds>  
  44.       </bpmndi:BPMNShape>  
  45.       <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">  
  46.         <omgdc:Bounds height="55.0" width="105.0" x="330.0" y="110.0"></omgdc:Bounds>  
  47.       </bpmndi:BPMNShape>  
  48.       <bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">  
  49.         <omgdc:Bounds height="55.0" width="105.0" x="500.0" y="110.0"></omgdc:Bounds>  
  50.       </bpmndi:BPMNShape>  
  51.       <bpmndi:BPMNShape bpmnElement="boundarytimer2" id="BPMNShape_boundarytimer2">  
  52.         <omgdc:Bounds height="30.0" width="30.0" x="405.0" y="150.0"></omgdc:Bounds>  
  53.       </bpmndi:BPMNShape>  
  54.       <bpmndi:BPMNShape bpmnElement="servicetask4" id="BPMNShape_servicetask4">  
  55.         <omgdc:Bounds height="55.0" width="105.0" x="500.0" y="210.0"></omgdc:Bounds>  
  56.       </bpmndi:BPMNShape>  
  57.       <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">  
  58.         <omgdi:waypoint x="105.0" y="137.0"></omgdi:waypoint>  
  59.         <omgdi:waypoint x="180.0" y="137.0"></omgdi:waypoint>  
  60.       </bpmndi:BPMNEdge>  
  61.       <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">  
  62.         <omgdi:waypoint x="301.0" y="139.0"></omgdi:waypoint>  
  63.         <omgdi:waypoint x="330.0" y="137.0"></omgdi:waypoint>  
  64.       </bpmndi:BPMNEdge>  
  65.       <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">  
  66.         <omgdi:waypoint x="435.0" y="137.0"></omgdi:waypoint>  
  67.         <omgdi:waypoint x="500.0" y="137.0"></omgdi:waypoint>  
  68.       </bpmndi:BPMNEdge>  
  69.       <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">  
  70.         <omgdi:waypoint x="605.0" y="137.0"></omgdi:waypoint>  
  71.         <omgdi:waypoint x="670.0" y="137.0"></omgdi:waypoint>  
  72.       </bpmndi:BPMNEdge>  
  73.       <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">  
  74.         <omgdi:waypoint x="420.0" y="180.0"></omgdi:waypoint>  
  75.         <omgdi:waypoint x="419.0" y="237.0"></omgdi:waypoint>  
  76.         <omgdi:waypoint x="500.0" y="237.0"></omgdi:waypoint>  
  77.       

    相關推薦

    Activiti定時任務示例

    工作流其實做的事情還是很多的,  這不,這周公司經理叫我在前段時間的基礎上,把專案中的一個客戶回訪計劃的提醒功能也加到工作流當中,對於沒有接觸過定時任務的我來說,又有的一番研究了。  在 咖啡兔 http://weibo.com/kafeituzi 的提醒下,使用了邊界定時事件 + Job的方式成功實現了,

    【linux】crontab的定時任務示例

    介紹 crontab是我們起定時任務用的,目前我是因為有個程式每天都要執行一遍,如果天天手動執行總有些傻,所以用crontab做了個定時任務,順便把2遇到的問題記錄一下。 因為cron的服務是linux內建的,所以我們不需要進行配置,直接使用就好了。

    使用java配置定時任務的幾種配置方式及示例

    遞增 exc trigge strong trigger except 字符 ssi uart Spring定時器,主要有兩種實現方式,包括Java Timer定時和Quartz定時器! 1.Java Timer定時 首先繼承java.util.TimerTask類實現

    Oracle 使用DBMS_JOB和DBMS_SCHEDULER 建立定時任務 建立管理job示例

      使用DBMS_JOB和DBMS_SCHEDULER建立、管理job示例 原創 Oracle 作者:Hoegh 時間:2015-04-28 16:52:41  6439  0     &

    Laravel框架定時任務2種實現方式示例

    本文例項講述了Laravel框架定時任務2種實現方式。分享給大家供大家參考,具體如下: 第一種 1、生成一個commands檔案 > php artisan make:command test 2、開啟檔案進行修改 laravel\App\Console\Commands\

    SpringSchedule - 定時任務(引數示例:Cron表示式)

    "0 0 12 * * ?" 每天中午十二點觸發 "0 15 10 ? * *" 每天早上10:15觸發 "0 15 10 * * ?" 每天早上10:15觸發 "0 15 10 * * ? *" 每天早上10:15觸發 "0 15 10 * * ? 2005" 2005年的每天

    JavaWeb三種常用的定時任務簡單示例

    (1)、程式碼如下: package com.sundy.task; import java.util.Timer; import java.util.TimerTask; import javax.servlet.ServletContextEvent; import javax.servle

    linux下新增定時任務 詳解示例

    linux下定時執行任務的方法 在Linux中你應該先輸入crontab -e,然後就會有個vi編輯介面,再輸入0 3 * * 1 /clearigame2內容到裡面 :wq 儲存退出。 在LINUX中,週期執行的任務一般由cron這個守護程序來處理[ps -ef|grep cron]。cron讀取一個或

    定時任務schedule(quartz)

    except depend within schedule second .class cut spa 定時 1, 簡介Quartz是一個任務調度框架。核心類:Scheduler :調度器,所有Job的調度都是由它控制;JobDetail :生成Job對象的實例,存儲

    linux設置定時任務

    希望 權限 style 2.0 linux系統 php ron date oca Linux 設置定時任務,執行PHP腳本 1.crontab -e 2.0 2 * * * /usr/local/php/bin/php /var/tmp/test.php > /var

    linux新建定時任務

    .sh div 定義 roc hour rac acl 一行 表示 linux/aix 使用crontab -e命令,再最後一行加入改功能腳本,例如: 10 12 * * * sh /oracle/orabak/orabak.sh 關於linux下crontab的使用  

    crontab定時任務

    roo 刪除 rontab port .py 絕對路徑 n) for 使用 crontab -e 0 4 * * * /root/scripts/mysqlbackup.sh 0 4 * * * /root/scripts/apacherestart.sh 0 5 * *

    使用cron命令配置定時任務(cron jobs)

    之間 inux 意見 通過 onos 一個 str b- arch 原文 http://www.cnblogs.com/end/archive/2012/02/21/2361741.html 把cron加入到啟動腳本中: # rc-update add vixie-c

    詳解java定時任務

    導致 println 正常 延遲執行 first 指定 線程終止 ont 打印 在我們編程過程中如果需要執行一些簡單的定時任務,無須做復雜的控制,我們可以考慮使用JDK中的Timer定時任務來實現。下面LZ就其原理、實例以及Timer缺陷三個方面來解析java Timer定

    Linux定時任務Crontab命令

    主目錄 日誌清理 文件中 定義 服務 系統命令 root spool 詳細 linux 系統則是由 cron (crond) 這個系統服務來控制的。Linux 系統上面原本就有非常多的計劃性工作,因此這個系統服務是默認啟動的。另 外, 由於使用者自己也可以設置計劃任務,所以

    Jenkins定時任務

    cnblogs build cal http 技術分享 nth 一次 執行 ges 在“構建觸發器”中勾選“Build periodically”選項 此處定時任務的格式遵循cron 的語法 星號(*):代表所有可能的值。例如,month 字段如果是星號,則表示在滿足其

    CentOS Crontab(定時任務)

    status stat ntsysv 設置 backup pda 啟動服務 brush 分鐘 安裝crontab: yum install crontabs 說明: service crond start //啟動服務 service crond stop //關閉服務 s

    linux定時任務crontab

    9.png linux .cn 命令 png alt nbsp ont 技術分享 *  *  *  *  *  command 分 時 日 月 周 命令 linux定時任務crontab

    oracle定時任務(dbms_job)

    eat 更改 gin session 啟動參數 code bin 之前 今天 今天總結下Oracle的任務隊列管理器(job queue ),以後也方便查詢. 我們要做定時任務時,有兩種辦法 一種是: 操作系統的定時,win的定時任務,unix的crontab一種是: 數據

    Java 定時任務

    檢查 安排 begin real clip 重復執行 定時任務 attribute 但是 在我們編程過程中如果需要執行一些簡單的定時任務,無須做復雜的控制,我們可以考慮使用JDK中的Timer定時任務來實現。下面LZ就其原理、實例以及Timer缺陷三個方面來解析Java