<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Oracle神諭

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      284 隨筆 :: 9 文章 :: 106 評論 :: 0 Trackbacks
     定時批處理作業是J2EE企業應用里很重要的一環,用來在晚間進行財務掛賬,數據轉存,新聞聯播等等操作。

        而在Spring里,已經很好的集成了Quartz,簡單到像配cron一樣,在xml文件里面配一下時間就可以自動執行,不需要寫一行代碼。Spring對Quartz大刀闊斧的簡化堪稱范例,Quartz項目組也許可以學習一下。

        <bean id="methodInvokingJobDetail"
            class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject"><ref bean="financeDAO"/></property>
            <property name="targetMethod"><value>confirmOrder</value></property>
        </bean>

        <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="methodInvokingJobDetail"/>
            </property>
            <property name="cronExpression">
                <value>0 0 6,12,20 * * ?</value>
            </property>
        </bean>
        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list><ref local="cronTrigger"/></list>
            </property>
        </bean>

    上面這段配置文件規定了在早上6點和晚上8點執行financeDAO對象的confirmOrder()方法.


    附:cronExpression配置說明

    字段   允許值   允許的特殊字符
      0-59   , - * /
      0-59   , - * /
    小時   0-23   , - * /
    日期   1-31   , - * ? / L W C
    月份   1-12 或者 JAN-DEC   , - * /
    星期   1-7 或者 SUN-SAT   , - * ? / L C #
    年(可選)   留空, 1970-2099   , - * /

    posted on 2005-07-20 21:37 java世界暢談 閱讀(15603) 評論(42)  編輯  收藏 所屬分類: Spring

    評論

    # re: Spring--簡單使用quartz實現定時作業 2005-11-06 18:41 else
    這么多人看了這篇日志,竟然沒人回復,太不厚道了,看來都是google過來的
    花了不短的時間仔細研究了quartz的內部代碼
    才發現spring都已經把事情做完了,sigh  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-11-08 11:57 wtigter
    不錯,允許的特殊字符,包括那些東西。  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-11-08 11:58 wtigter
    能解釋下后面的字符的用法嗎?
    wtigter@163.com  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-11-08 12:04 wtigter
    <property name="cronExpression">
    <value>0 0 6,12,20 * * ?</value>
    </property>

    這里是6,12,20,怎么你說是定時在
    在早上6點和晚上8點執行

    那12點不執行嗎  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-11-08 14:12 wtigter
    The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".
    “*”字符被用來指定所有的值。如:”*“在分鐘的字段域里表示“每分鐘”。
    The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification.
    “?”字符只在日期域和星期域中使用。它被用來指定“非明確的值”。當你需要通過在這兩個域中的一個來指定一些東西的時候,它是有用的。看下面的例子你就會明白。
    The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
    “-”字符被用來指定一個范圍。如:“10-12”在小時域意味著“10點、11點、12點”。
    The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
    “,”字符被用來指定另外的值。如:“MON,WED,FRI”在星期域里表示”星期一、星期三、星期五”.
    The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety.
    The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
    The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days.
    The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month".
    The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month.
    The 'C' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "calendar". This means values are calculated against the associated calendar, if any. If no calendar is associated, then it is equivalent to having an all-inclusive calendar. A value of "5C" in the day-of-month field means "the first day included by the calendar on or after the 5th". A value of "1C" in the day-of-week field means "the first day included by the calendar on or after sunday".
      回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-11-19 10:30 kcb
    請問,如果所執行的方法需要用戶提供參數應該怎么做?謝謝!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-12-14 10:42 丫梨
    嗨,那你能不能告訴我,如何在服務器啟動的時候就調用某個類中的一個方法呢?我想這個方法只在服務器啟動的時候才調用一次。如果你知道的話,請告訴我哦,我的郵箱是wjljava@163.com,真的是非常感謝!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-12-14 23:37 jon
    我也用這個,配置的是<property name="cronExpression">
    <value>0 0 3 * * ?</value>
    </property>早上3點運行,在TOMCAT下能很好啟動一次任務,而在SUNONE服務器下,會同時啟動兩個定時任務,真奇怪,搞得插入記錄總是重復,且重復生成的時間只相差幾秒而已,有哪位知道呀?  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2005-12-14 23:38 jon
    我的EMAIL:jon.xiong@163.com  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-03-08 15:19 klt8848
    好東東!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-04-03 10:14 avgi
    @丫梨
    可以在spring初始化bean時做點手腳。  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-05-18 10:32 對沖
    @kcb
    @wtigter
    應該執行吧,估計是少寫了  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-06-21 14:59 frankie
    好東西!為了避免被說不厚道,嘿嘿
      回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-07-31 17:58 長征路上的妖怪
    有人用quartz嗎?CronTrigger中的若干個構造方法中的String類型是什么用處呢?  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-08-03 17:11 flyhawk1010
    好文!正好項目要用到!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-08-04 10:28 潘曉歡
    financeDAO對象怎么建立,能不能給完整點
    ÷  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-08-04 12:51 terry0431
    怎樣實現動態設置任務?不重起服務  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-08-10 14:04 kevin.guo
    quartz的高級特性不僅如此
    1 數據庫存儲
    2 集群支持
    3 數據庫持久化任務,trigger
    4 trigger 的停止,運行
    5 任務的任意添加
    6 比corntrigger 更詳盡的任務安排
    7 線程的內部數據交換  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-09-11 15:14 gLaiVe
    @kevin.guo

    你說的trigger的停止,能不能動態設置的呢,比如我想在任何時刻停止當前正在跑得task,我現在的quartz是配置在spring里面了,怎么用spring來控制  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-09-16 18:05 xiaqingfeng
    為什么我照你的寫會出一個異常
    Failure obtaining db row lock: Table 'onhave.qrtz_locks' doesn't exist [See nested exception: java.sql.SQLException: Table 'onhave.qrtz_locks' doesn't exist]  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-09-18 22:39 xiaqingfeng
    請高手指點一下啊,為什么會報異常?難道一定要建表嗎?可我不想建表  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2006-11-03 18:25 kevin.guo
    你說的trigger的停止,能不能動態設置的呢,

    我沒用spring集成,做法是job里調用trigger的停方法,這樣trigger驅動的job都不會被執行了  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2007-03-21 16:29 helloint
    cronExpression配置說明

    這個說的太簡單拉..  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2007-04-10 11:08 houhy
    一個cron表達式有至少6個(也可能是7個)由空格分隔的時間元素。從左至右,這些元素的定義如下:

    1.秒(0–59)

    2.分鐘(0–59)

    3.小時(0–23)

    4.月份中的日期(1–31)

    5.月份(1–12或JAN–DEC)

    6.星期中的日期(1–7或SUN–SAT)

    7.年份(1970–2099)  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2007-11-06 18:14 fenix
    好  回復  更多評論
      

    # re:sss 2007-11-26 10:13 dfsf
    Good java spring   回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2007-11-28 14:32 meizi
    真棒??!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-01-02 23:01 linuxboy
    VERY good!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-01-09 15:54 quarts
    多謝樓主,不錯的文章。我通過你的文章配置了Quarts的應用,但在tomcat上使用時,出現過只能采集一次,之后那線程一直阻塞狀態沒法定時下去,該怎么辦?  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 [未登錄] 2008-01-21 12:28 leo
    up 。。。。。。。。。  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-01-28 10:07 df
    good  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 [未登錄] 2008-03-30 09:29 aa
    good
      回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-04-11 13:34 初級
    <bean id="fileWriteTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail">
    <ref bean="fileWriteDetail"/>
    </property>
    <property name="cronExpression">
    <value>0 27 10 ? * *</value>
    </property>
    </bean>
    這個job執行了一次,我修改為“<value>0 27 13 ? * *</value>”就不再自動執行,再改為其他時間,也不再自動執行。我重啟服務也沒用。誰遇見到這個問題?。?nbsp; 回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-05-19 09:30 asd
    不錯,學習了。  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-07-18 16:37 zlj
    學習中。。。  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-07-30 18:03 飛越海面
    我想請問一下對于現在的spring中集成的還是這樣的配置方式嗎?  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-07-31 15:26 black_boy
    太好了,解了我燃眉之急  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 [未登錄] 2008-08-24 13:51 wz
    正要用這個,好啊,謝謝!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2008-10-27 16:00 9527
    為什么我跟你寫的一樣 但是我的TOMCAT啟動之后 沒有反應呢?請高手指點 多謝啦  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2009-01-13 22:14 odin
    真慶幸可以看到你的文章,對我太有幫助了!  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2009-10-19 14:34 coding
    不錯 很有幫助 學習了  回復  更多評論
      

    # re: Spring--簡單使用quartz實現定時作業 2009-12-04 19:35 baizhiguo
    我的配置文件和你的一樣但是就是報錯:錯誤內容是找不到:org.springframework.scheduling.quartz.CronTriggerBean,那個包也有了  回復  更多評論
      

    主站蜘蛛池模板: 亚洲AV日韩综合一区尤物| 亚洲AV无码国产剧情| 野花视频在线官网免费1| 久久国产免费观看精品| 成年女人毛片免费视频| 亚洲精品乱码久久久久66| 亚洲综合久久精品无码色欲| 三上悠亚在线观看免费| 成全视频免费高清| 亚洲AV无码国产精品麻豆天美| 亚洲熟妇AV乱码在线观看| 日本黄色动图免费在线观看| 日本一道高清不卡免费| 亚洲黄色片在线观看| 一级做a免费视频观看网站| 特级做A爰片毛片免费69| 亚洲国产一成人久久精品| 欧洲亚洲综合一区二区三区| 日韩在线不卡免费视频一区| 高清在线亚洲精品国产二区| 亚洲免费视频网址| 叮咚影视在线观看免费完整版| 日韩人妻无码免费视频一区二区三区| 亚洲综合一区二区国产精品| 视频一区在线免费观看| 99久久综合国产精品免费| 亚洲av无码一区二区三区不卡| 色www免费视频| 热久久精品免费视频| 亚洲欧洲精品一区二区三区| 中文字幕一区二区免费| 国产一级淫片a免费播放口之| 亚洲激情校园春色| 午夜免费啪视频在线观看 | 黄色网址免费观看| 亚洲欧洲国产精品香蕉网| 立即播放免费毛片一级| 成年美女黄网站18禁免费| 亚洲视屏在线观看| 久久国产精品免费专区| 一本色道久久综合亚洲精品|