Spring 配置Quartz 定时任务调度服务

在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 , - * /

 常用示例:
 


0 0 12 * * ?每天12点触发
0 15 10 ? * *每天10点15分触发
0 15 10 * * ?每天10点15分触发
0 15 10 * * ? *每天10点15分触发
0 15 10 * * ? 20052005年每天10点15分触发
0 * 14 * * ?每天下午的 2点到2点59分每分触发
0 0/5 14 * * ?每天下午的 2点到2点59分(整点开始,每隔5分触发)
0 0/5 14,18 * * ?每天下午的 2点到2点59分(整点开始,每隔5分触发)
每天下午的 18点到18点59分(整点开始,每隔5分触发)
0 0-5 14 * * ?每天下午的 2点到2点05分每分触发
0 10,44 14 ? 3 WED3月分每周三下午的 2点10分和2点44分触发
0 15 10 ? * MON-FRI从周一到周五每天上午的10点15分触发
0 15 10 15 * ?每月15号上午10点15分触发
0 15 10 L * ?每月最后一天的10点15分触发
0 15 10 ? * 6L每月最后一周的星期五的10点15分触发
0 15 10 ? * 6L 2002-2005从2002年到2005年每月最后一周的星期五的10点15分触发
0 15 10 ? * 6#3每月的第三周的星期五开始触发
0 0 12 1/5 * ?每月的第一个中午开始每隔5天触发一次
0 11 11 11 11 ?每年的11月11号 11点11分触发(光棍节)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值