java quartz添加任务_Java Quartz定时任务的实现

Java Quartz定时任务的实现

首先,实现quartz定时任务只需要俩个条件:

一、在web项目中新建一个quartz.xml文件,下面是XML文件的示例代码。

二、根据quartz.xml文件中的任务写对应的service任务实现类

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:context="http://www.springframework.org/schema/context";

xmlns:aop="http://www.springframework.org/schema/aop"; xmlns:util="http://www.springframework.org/schema/util";

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-3.0.xsd

">

class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

30 4,4/5 9/1 * * ?

35 4,4/5 9/1 * * ?

55 4,4/5 9/1 * * ?

quartz.xml文件需要注意俩个点:

* org.springframework.scheduling.quartz.SchedulerFactoryBean的任务调度

* cronExpression表达式的理解和使用

从左到右为 :

“*”字符被用来指定所有的值。如:”*“在分钟的字段域里表示“每分钟”。

“-”字符被用来指定一个范围。如:“10-12”在小时域意味着“10点、11点、12点”。

“,”字符被用来指定另外的值。如:“MON,WED,FRI”在星期域里表示”星期一、星期三、星期五”.

“?”字符只在日期域和星期域中使用。它被用来指定“非明确的值”。当你需要通过在这两个域中的一个来指定一些东西的时候,它是有用的。看下面的例子你就会明白。

“L”字符指定在月或者星期中的某天(最后一天)。即“Last ”的缩写。但是在星期和月中“L”表示不同的意思,如:在月子段中“L”指月份的最后一天-1月31日,2月28日,如果在星期字段中则简单的表示为“7”或者“SAT”。如果在星期字段中在某个value值得后面,则表示“某月的最后一个星期value”,如“6L”表示某月的最后一个星期五。

“W”字符只能用在月份字段中,该字段指定了离指定日期最近的那个星期日。

“#”字符只能用在星期字段,该字段指定了第几个星期value在某月中

quarzt对应的XQuartzService

package com.xunxin.config;

/**

* Copyright © 2017 noseparte(Libra) © Like the wind, like rain

* @Author Noseparte

* @Compile 2017年11月30日 -- 下午3:44:57

* @Version 1.0

* @Description 定时调度任务

*/

public class XQuartzService {

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值