我的漫漫程序之旅

          專注于JavaWeb開發
          隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
          數據加載中……

          Quartz 關于CronTrigger 的 深入

          CronTrigger是比SimpleTrigger更為有用的.如果你想啟動一個工作任務,像日歷進程一樣.
          這個時候CronTrigger是比SimpleTrigger更為精確的.

          比如你可以指定: "每個星期五的下午","每個周末的上午9:30","每周一,周三的上午9點到10點,每5分鐘一次"

          這都需要Cron Excepressions 來描述.

          Cron-Excepressions是用來配置CronTrigger實例的.它有7個精確的子表達式,其中年是可選的.順序如下:

          1. Seconds
          2. Minutes
          3. Hours
          4. Day-of-Month
          5. Month
          6. Day-of-Week
          7. Year (optional field)
          讓我們來看看這個表達式的意思:

          "0 0 12 ? * WED"

          表示每個星期三的中午12點

          個別的子表達式是允許包含集合的,比如"MON, WED, FRI", 或  "MON-WED,SAT"
          中間用,號隔開.

          其中 * 號是代碼 "每" 的意思,就是此屬性的每一個可能值.
          在這里表示every Wednesday.

          ?號用在 day-of-month 和 day-of-week  屬性上.

          L代表Last,W代表Weekend

          #號指定每月的第幾個星期幾.如:FRI#3 意思是每月的第三個星期五.

          這有一些例子大家參考一下:

          Expression   Meaning 
          "0 0 12 * * ?"    Fire at 12pm (noon) every day 
          "0 15 10 ? * *"    Fire at 10:15am every day 
          "0 15 10 * * ?"    Fire at 10:15am every day 
          "0 15 10 * * ? *"    Fire at 10:15am every day 
          "0 15 10 * * ? 2005"    Fire at 10:15am every day during the year 2005  
          "0 * 14 * * ?"    Fire every minute starting at 2pm and ending at 2:59pm, every day  
          "0 0/5 14 * * ?"    Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day  
          "0 0/5 14,18 * * ?"    Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day  
          "0 0-5 14 * * ?"    Fire every minute starting at 2pm and ending at 2:05pm, every day  
          "0 10,44 14 ? 3 WED"    Fire at 2:10pm and at 2:44pm every Wednesday in the month of March.  
          "0 15 10 ? * MON-FRI"    Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday  
          "0 15 10 15 * ?"    Fire at 10:15am on the 15th day of every month  
          "0 15 10 L * ?"    Fire at 10:15am on the last day of every month  
          "0 15 10 ? * 6L"    Fire at 10:15am on the last Friday of every month  
          "0 15 10 ? * 6L"    Fire at 10:15am on the last Friday of every month  
          "0 15 10 ? * 6L 2002-2005"    Fire at 10:15am on every last friday of every month during the years 200220032004 and 2005  
          "0 15 10 ? * 6#3"    Fire at 10:15am on the third Friday of every month 
          使用此類也是很簡單的,比如你可以用如下代碼來替換SimpleTrigger部分:
          CronTrigger cronTrigger = new CronTrigger("myTrigger","myGroup","你的表達式");

          對于此部分大家沒必要全部記住,需要的時候去查API就行了.



          posted on 2008-05-08 17:44 々上善若水々 閱讀(4422) 評論(0)  編輯  收藏 所屬分類: opensource

          主站蜘蛛池模板: 承德市| 成安县| 镇康县| 阿合奇县| 青铜峡市| 吉林市| 富源县| 朔州市| 海丰县| 平顶山市| 扎鲁特旗| 柳江县| 边坝县| 子长县| 广河县| 普定县| 彭山县| 四会市| 建阳市| 巍山| 安吉县| 苏尼特左旗| 四川省| 五莲县| 仙居县| 吴桥县| 三台县| 南陵县| 恭城| 铜鼓县| 平安县| 梨树县| 玉树县| 克什克腾旗| 东光县| 莱芜市| 云浮市| 黄陵县| 阳高县| 繁峙县| 滨州市|