我的漫漫程序之旅

          專注于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

          主站蜘蛛池模板: 和政县| 闻喜县| 九江市| 称多县| 宝坻区| 哈巴河县| 定结县| 乡城县| 龙川县| 莱西市| 永年县| 郯城县| 古浪县| 平阴县| 神农架林区| 兴文县| 东乌| 丹东市| 濉溪县| 雷州市| 习水县| 唐河县| 绥宁县| 黎川县| 进贤县| 阳曲县| 瓮安县| 巴南区| 广水市| 滨州市| 寿宁县| 凯里市| 西林县| 原阳县| 大连市| 方城县| 绵阳市| 黄骅市| 昌乐县| 潜江市| 石阡县|