posts - 29, comments - 0, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Spring 配置Quartz 定時任務調度服務

          Posted on 2007-05-28 15:37 change 閱讀(704) 評論(0)  編輯  收藏

          在ApplicationContext.xml 里面的配置:


          <!-- begin day -->

          <bean id="Initlogdatatarget" class="com.sotrip.statistic.scheduling.Initlogdata">
           <property name="tlogvisitDAO"><ref local="tlogvisitDAO"/></property>
           </bean>
          <bean id="Jobfortimerdaysservice"
               class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
           <property name="transactionManager"><ref local="transactionManager"/></property>
           <property name="target"><ref local="Initlogdatatarget"/></property>
           <property name="transactionAttributes">
            <props>  
             <prop key="exec*">PROPAGATION_REQUIRED</prop>
            </props>
           </property>
          </bean>

          <bean id="methodInvokingJobDetail"
           class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!--**** 此處的 targetObject 所指定的bean Jobfortimerdaysservice 需是service層的,通過它定義的事務屬性 就可以使得 targetMethod 所定義的方法具有事務屬性。-->
           <property name="targetObject"><ref bean="Jobfortimerdaysservice"/></property>
           <property name="targetMethod"><value>execute</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/2 * * * ?</value>
           </property>
          </bean>

          <!-- end day-->

          <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
           <property name="triggers">
            <list>
          <!--  <ref local="cronTriggertest"/>-->
             <ref local="cronTrigger"/>
              <ref local="cronTriggermonth"/><!-- 此處可以配置多個trigger-->
            </list>
           </property>
          </bean>

          在就是定時時間的定義:

          Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that are actually made up of seven sub-expressions, that describe individual details of the schedule. These sub-expression are separated with white-space, and represent:

          1. Seconds
          2. Minutes
          3. Hours
          4. Day-of-Month
          5. Month
          6. Day-of-Week
          7. Year (optional field)

          An example of a complete cron-expression is the string "0 0 12 ? * WED" - which means "every Wednesday at 12:00 pm".

          cronExpression配置說明

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

           


          主站蜘蛛池模板: 团风县| 锡林郭勒盟| 商丘市| 安平县| 安国市| 成安县| 临澧县| 徐水县| 安义县| 尚义县| 临沭县| 文登市| 双桥区| 巴塘县| 丹棱县| 禄丰县| 特克斯县| 西城区| 临泽县| 西吉县| 姚安县| 布拖县| 江永县| 伊金霍洛旗| 西平县| 白山市| 大荔县| 临泉县| 冕宁县| 绥棱县| 革吉县| 东平县| 武功县| 扶余县| 自贡市| 屯门区| 饶阳县| 诸城市| 惠州市| 长沙县| 丰顺县|