spring 任务调度,定时器服务

 一个Cron-表达式是一个由六至七个字段组成由空格分隔的字符串,其中6个字段是必须的而一个是可选的,如下:
字段名  允许的值  允许的特殊字符
秒  0-59  , - * /
分  0-59  , - * /
小时  0-23  , - * /
日  1-31  , - * ? / L W C
月  1-12 or JAN-DEC  , - * /
周几  1-7 or SUN-SAT  , - * ? / L C #
年 (可选字段)  empty, 1970-2099  , - * /


'*' 字符可以用于所有字段,在“分”字段中设为"*"表示"每一分钟"的含义。

'?' 字符可以用在“日”和“周几”字段. 它用来指定 '不明确的值'. 这在你需要指定这两个字段中的某一个值而不是另外一个的时候会被用到。在后面的例子中可以看到其含义。

'-' 字符被用来指定一个值的范围,比如在“小时”字段中设为"10-12"表示"10点到12点".

',' 字符指定数个值。比如在“周几”字段中设为"MON,WED,FRI"表示"the days Monday, Wednesday, and Friday".

'/' 字符用来指定一个值的的增加幅度. 比如在“秒”字段中设置为"0/15"表示"第0, 15, 30, 和 45秒"。而 "5/15"则表示"第5, 20, 35, 和 50". 在'/'前加"*"字符相当于指定从0秒开始. 每个字段都有一系列可以开始或结束的数值。对于“秒”和“分”字段来说,其数值范围为0到59,对于“小时”字段来说其为0到23, 对于“日”字段来说为0到31, 而对于“月”字段来说为1到12。"/"字段仅仅只是帮助你在允许的数值范围内从开始"第n"的值。 因此 对于“月”字段来说"7/6"只是表示7月被开启而不是“每六个月”, 请注意其中微妙的差别。

'L'字符可用在“日”和“周几”这两个字段。它是"last"的缩写, 但是在这两个字段中有不同的含义。例如,“日”字段中的"L"表示"一个月中的最后一天" —— 对于一月就是31号对于二月来说就是28号(非闰年)。而在“周几”字段中, 它简单的表示"7" or "SAT",但是如果在“周几”字段中使用时跟在某个数字之后, 它表示"该月最后一个星期×" —— 比如"6L"表示"该月最后一个周五"。当使用'L'选项时,指定确定的列表或者范围非常重要,否则你会被结果搞糊涂的。

'W' 可用于“日”字段。用来指定历给定日期最近的工作日(周一到周五) 。比如你将“日”字段设为"15W",意为: "离该月15号最近的工作日"。因此如果15号为周六,触发器会在14号即周五调用。如果15号为周日, 触发器会在16号也就是周一触发。如果15号为周二,那么当天就会触发。然而如果你将“日”字段设为"1W", 而一号又是周六, 触发器会于下周一也就是当月的3号触发,因为它不会越过当月的值的范围边界。'W'字符只能用于“日”字段的值为单独的一天而不是一系列值的时候。

'L'和'W'可以组合用于“日”字段表示为'LW',意为"该月最后一个工作日"。

'#' 字符可用于“周几”字段。该字符表示“该月第几个周×”,比如"6#3"表示该月第三个周五( 6表示周五而"#3"该月第三个)。再比如: "2#1" = 表示该月第一个周一而 "4#5" = 该月第五个周三。注意如果你指定"#5"该月没有第五个“周×”,该月是不会触发的。

'C' 字符可用于“日”和“周几”字段,它是"calendar"的缩写。 它表示为基于相关的日历所计算出的值(如果有的话)。如果没有关联的日历, 那它等同于包含全部日历。“日”字段值为"5C"表示"日历中的第一天或者5号以后",“周几”字段值为"1C"则表示"日历中的第一天或者周日以后"。

对于“月份”字段和“周几”字段来说合法的字符都不是大小写敏感的。

下面是一些完整的例子:
表达式  含义
"0 0 12 * * ?"  每天中午十二点触发
"0 15 10 ? * *"  每天早上10:15触发
"0 15 10 * * ?"  每天早上10:15触发
"0 15 10 * * ? *"  每天早上10:15触发
"0 15 10 * * ? 2005"  2005年的每天早上10:15触发
"0 * 14 * * ?"  每天从下午2点开始到2点59分每分钟一次触发
"0 0/5 14 * * ?"  每天从下午2点开始到2:55分结束每5分钟一次触发
"0 0/5 14,18 * * ?"  每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发
"0 0-5 14 * * ?"  每天14:00至14:05每分钟一次触发
"0 10,44 14 ? 3 WED"  三月的每周三的14:10和14: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"  每月最后一个周五的10:15触发
"0 15 10 ? * 6L 2002-2005"  2002年至2005年的每月最后一个周五的10:15触发
"0 15 10 ? * 6#3"  每月的第三个周五的10:15触发

 

spring 定时器  配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-lazy-init="false">


<bean id="job1" class="com.job.Job1" />//任务1
<bean id="job2" class="com.job.Job2" />//任务2

<bean id="jobDetail_1"
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
   <property name="targetObject">
    <ref bean="job1" />
   </property>
   <property name="targetMethod">
    <value>jobMethod1</value>//执行的方法
   </property>
</bean>
<bean id="jobDetail_2"
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
   <property name="targetObject">
    <ref bean="job2" />
   </property>
   <property name="targetMethod">
    <value>jobMethod2</value>
   </property>
</bean>

<bean id="cronTrigger_1"
   class="org.springframework.scheduling.quartz.CronTriggerBean">
   <property name="jobDetail">
    <ref bean="jobDetail_1" />
   </property>
   <property name="cronExpression">
    <value>0 0 0 * * ?</value>//每天凌晨12点执行一次
   </property>

</bean>
<bean id="cronTrigger_2"
   class="org.springframework.scheduling.quartz.CronTriggerBean">
   <property name="jobDetail">
    <ref bean="jobDetail_2" />
   </property>
   <property name="cronExpression">
    <value>0 0 */1 * * ?</value>//每小时执行一次
   </property>
</bean>

<bean
   class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
   <property name="triggers">
    <list>
     <ref local="cronTrigger_1" />
     <ref local="cronTrigger_2" />
    </list>
   </property>
</bean>

</beans>

Spring Quartz定时详情


在Spring中,使用JDK的Timer类库来做任务调度功能不是很方便,关键它不可以象cron服务那样可以指定具体年、月、日、时和分的时间。你只能将时间通过换算成微秒后传给它。如任务是每天执行一次,则需要在spring中如下配置:
­
<bean id="scheduledTask" class= "org.springframework.scheduling.timer.ScheduledTimerTask">
<!--程序启动后开始执行任务的延迟时间 -->
<property name="delay" value="0" />
<!--每隔一天【一天=24×60×60×1000微秒】执行一次-->
<property name="period" value="86400000" />
<!--业务统计报表bean -->
<property name="timerTask" ref="businessReport" />
</bean>
­
其中period就是一天的微秒数。如果每月1日运行一次,那就复杂了,不知如何配置。因为月份有大、小月之分,每月的微秒数都不一样。
­
而Quartz类库不但有着上述JDK的Timer类库类似的配置,更重要的,它还有着类似于unix的cron服务的配置。因此,在迁移中我们采用了Quartz类库的接口。
­
Quartz可以通过两种方式来调度程序:一是使用Spring提供的 MethodInvokingJobDetailFactoryBean 代理类,Quartz通过该代理类直接调度任务类的某个函数;二是任务类继承并实现Quartz接口,Quartz通过该接口进行调度。
­
如果采用第一种方式,即由Quartz直接调度任务类的某个接口,那么,业务类是不必进行任何修改的。我们的业务类大概如下
­
public class BusinessReport {
    public void perform(){ //执行报表统计入口函数
        //业务逻辑
    }
}
­
第一步,在Spring配置文件中增加本业务类
­
<bean id=" businessReport " class=" BusinessReport "/>
­
第二步,定义任务。在Spring配置文件中配置代理类MethodInvokingJobDetailFactoryBean,定义任务的详细信息。
­
<bean id=" reportTask " class= "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name=" targetObject " ref=" businessReport " />
<property name=" targetMethod " value=" perform " />
<property name=" concurrent " value=" false " />
</bean>
­
这个配置告诉Spring,我们的任务是执行id为businessReport的bean中的perform函数。其中参数concurrent告诉Spring,不要并发运行这个任务。
­
第三步,配置一个触发器。在Spring配置文件中配置触发器类CronTriggerBean 。
­
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref=" reportTask " />
    <property name="cronExpression" value="0 0 1 1 * ?" />
</bean>
­
触发器将告诉Quartz两件事:在何时触发任务、触发哪个任务。其中属性参数cronExpression为 调度时间,格式和unix上的crontab类似,具体见下表1。“0 0 1 1 * ?”表示每月1日凌晨1点运行。其中问号表示忽略该位置(星期)上的值。属性参数jobDetail指向具体的任务bean:reportTask 。如果你有多个任务,每个任务的触发时间都不一样,则你可以在此配置多个不同的触发器。
­
表1. cronExpression的时间格式
位置 - 含义­
1 - 秒(0–59)
­2 - 分(0–59)
3 - 时(0–23)
­4 - 日(1–31)
­5 - 月(1–12)
­6 - 星期(SUN–SAT or 1–7)
­7 - 年(可选, 1970–2099)

第四步,配置一个调度器。在Spring配置文件中配置调度器类SchedulerFactoryBean。


<bean class= "org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
      <list>
            <ref bean="cronTrigger" />
       </list>
    </property>
</bean>
­
该调度器用于管理触发器。只有在调度器中列表出现的触发器才被Quartz系统调度执行。至此,所有的配置已完成,任务已能正常跑了。
­
如果采用第二种方式,那业务类是要进行小小的修改。整个过程如下。
­
第一步,修改上述的业务类,修改如下:
­
public class BusinessReport implements org.quartz.Job { //继承quartz 的job接口
    //实现job接口的execute函数,在其中简单调用perform()函数就可以了。
    public void execute(org.quartz.JobExecutionContext context){ //执行报表统计入口函数
       perform()
    }
    //其它的保持不变。
    public void perform(){ //执行报表统计入口函数
        //业务逻辑
    }
}
­
修改过程比较简单,只增加了两三行代码。
­
第二步,定义任务。在Spring配置文件中配置如下任务的详细信息。
­
<bean name=" reportTask " class= "org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value=" BusinessReport " />
</bean>
­
此配置告诉Quartz,我们的任务类的名字为BusinessReport。在定时触发时,Quartz会利用该类名来创建任务的实例,并执行该实例的execute方法。
­
第三、第四步与第一种的调度方式相应的步骤一样。
­
按第二种方式,整个Spring的配置文件如下:
­

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>­ <!-- 我们的任务 --> <bean name=" reportTask " class= "org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value=" BusinessReport " /></bean>­ <!-- 触发器 --> <bean id="cronTrigger" class= "org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --><property name="jobDetail" ref=" reportTask " /> <!-- 每月1日凌晨1点运行 --> <property name="cronExpression" value="0 0 1 1 * ?" /></bean>­ <!-- 调度器 --> <bean class= "org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"><list><!-- 触发器列表--> <ref bean="cronTrigger" /></list></property></bean> </beans>

 

附: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:00触发
0 15 10 ? * *---------------每天上午10:15 触发
0 15 10 * * ?---------------每天上午10:15 触发
0 15 10 * * ? *---------------每天上午10:15 触发
0 15 10 * * ? 2005---------------在2005年中的每天上午10:15 触发
0 * 14 * * ?---------------每天在下午2:00至2:59之间每分钟触发一次
0 0/5 14 * * ?---------------每天在下午2:00至2:59之间每5分钟触发一次
0 0/5 14,18 * * ?---------------每天在下午2:00至2:59和6:00至6:59之间的每5分钟触发一次
0 0-5 14 * * ?---------------每天在下午2:00至2:05之间每分钟触发一次
0 10,44 14 ? 3 WED---------------每三月份的星期三在下午2:00和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, 2003, 2004 and 2005年的每个月的最后一个星期五的上午10:15触发
0 15 10 ? * 6#3---------------在每个月的第三个星期五的上午10:15触发
0 0 12 1/5 * ?---------------从每月的第一天起每过5天的中午12:00时触发
0 11 11 11 11 ?---------------在每个11月11日的上午11:11时触发.­

参考资料:
1.
http://www.springframework.org Spring的官方网站
2.
http://www.opensymphony.com/quartz/ Quartz的官方网站

程序逻辑:web.xml添加

<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/config/applicationContext.xml</param-value> </context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>applicationContext.xml文件内容如下: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="remindQuartz" class="test.quartz.RemindQuartz"/> <bean id="remindQuartzTask" class= "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="remindQuartz" /> <property name="targetMethod" value="perform" /> <property name="concurrent" value="false" /></bean> <!-- 调度器 --> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="remindQuartzTask" /> <property name="cronExpression" value="0 0 1 1 * ?" /></bean> </beans>

附:实际代码*

xml:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "><!-- quartz scheduler实例在spring中的初始化和自动运行 --> <bean id="timerJob" class="com.eduwo.application.web.evaluationSheets.TimerJob"> <property name="evaluationSheetService"> <ref bean="evaluationSheetService"/></property> </bean> <bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"><ref bean="timerJob"/></property> <property name="targetMethod"><value>doJob</value></property> <property name="concurrent" value="false"/></bean> <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="methodInvokingJobDetail"/> </property> <property name="cronExpression" value="0 0/60 * ? * * *" /> </bean> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false"> <property name="configLocation" value="classpath:quartz.properties" /> <property name="triggers"><list><ref local="simpleTrigger"/> </list></property></bean></beans>

 

JAVA类:

package com.eduwo.application.web.evaluationSheets; import java.util.Date;import org.apache.log4j.Logger; import com.eduwo.application.service.evaluationSheets.EvaluationSheetService; public class TimerJob {Logger logger=Logger.getLogger(TimerJob.class); private EvaluationSheetService evaluationSheetService; public EvaluationSheetService getEvaluationSheetService() { return evaluationSheetService;}public void setEvaluationSheetService( EvaluationSheetService evaluationSheetService) { this.evaluationSheetService = evaluationSheetService;}public void doJob(){ Date d =new Date(); logger.info("Quartz begin ------------------------------"+d.toLocaleString()+"-----"+d.getHours()); //评估单过期处理evaluationSheetService.updateExpiredEvaluationSheet(); logger.info("Quartz end ------------------------------");} } public void updateExpiredEvaluationSheet() { // TODO Auto-generated method stub Date date=new Date(System.currentTimeMillis()-2*24*60*60*1000); SimpleDateFormat formattxt=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String timejob=formattxt.format(date); String hql="select count(*) from ComTevaluationsheet sheet where sheet.updatedate is not null" +" and sheet.expired='0' and sheet.status in ('1','2') and sheet.updatedate<=to_date('" + timejob + "'," + "'" + "yyyy-mm-dd hh24:mi:ss')";List list=new ArrayList();list=this.get(hql); int count=0;if(list!=null&&list.size()>0) count=(Integer)list.get(0); if(count>0){System.out.println("start---"); hql="select sheet from ComTevaluationsheet sheet where sheet.updatedate is not null" +" and sheet.expired='0' and sheet.updatedate<=to_date('" + timejob + "'," + "'" + "yyyy-mm-dd hh24:mi:ss')";list = this.get(hql); for (int i = 0; i < list.size(); i++) { ComTevaluationsheet comTevaluationsheet=(ComTevaluationsheet) list.get(i); comTevaluationsheet.setExpired("1");comTevaluationsheet.setStatus("3"); //this.updateComTevaluationsheet(comTevaluationsheet);}}}

各种企业应用几乎都会碰到任务调度的需求,就拿论坛来说:每隔半个小时生成精华文章的RSS文件,每天凌晨统计论坛用户的积分排名,每隔30分钟执行锁定用户解锁任务。对于一个典型的MIS系统来说,在每月1号凌晨统计上个月各部门的业务数据生成月报表,每半个小时查询用户是否已经有快到期的待处理业务……,这样的例子俯拾皆是,不胜枚举。

    Quartz 在开源任务调度框架中的翘首,它提供了强大任务调度机制,难能可贵的是它同时保持了使用的简单性。Quartz 允许开发人员灵活地定义触发器的调度时间表,并可以对触发器和任务进行关联映射。
Spring为创建Quartz的Scheduler、Trigger和JobDetail提供了便利的FactoryBean类,以便能够在Spring 容器中享受注入的好处。此外Spring还提供了一些便利工具类直接将Spring中的Bean包装成合法的任务。Spring进一步降低了使用Quartz的难度,能以更具Spring风格的方式使用Quartz。概括来说它提供了两方面的支持:
    1)为Quartz的重要组件类提供更具Bean风格的扩展类;
    2)提供创建Scheduler的BeanFactory类,方便在Spring环境下创建对应的组件对象,并结合Spring容器生命周期进行启动和停止的动作。
配置文件:

Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz

首先我们来写一个被调度的类:

package com.kay.quartz;public class QuartzJob{ public void work() { System.out.println("Quartz的任务调度!!!"); }}

 Spring的配置文件:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- 要调用的工作类 --> <bean id="quartzJob" class="com.kay.quartz.QuartzJob"></bean> <!-- 定义调用对象和调用对象的方法 --> <bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject"> <ref bean="quartzJob"/> </property> <!-- 调用类中的方法 --> <property name="targetMethod"> <value>work</value> </property> </bean> <!-- 定义触发时间 --> <bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="jobtask"/> </property> <!-- cron表达式 --> <property name="cronExpression"> <value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value> </property> </bean> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime"/> </list> </property> </bean> </beans>

 测试程序:

 package com.kay.quartz; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MainTest{ /** * @param args */ public static void main(String[] args) { System.out.println("Test start."); ApplicationContext context = new ClassPathXmlApplicationContext("quartz-config.xml"); //如果配置文件中将startQuertz bean的lazy-init设置为false 则不用实例化 //context.getBean("startQuertz"); System.out.print("Test end.."); }}

 注意:项目中需要加载需要加入spring.jar   quartz-all-1.6.0.jar    commons-collections.jar   commons-logging.jar这几个包

 

关于cron表达式(来自网络):

Cron 表达式包括以下 7 个字段:



小时
月内日期

周内日期
年(可选字段)
Cron 触发器利用一系列特殊字符,如下所示:

反斜线(/)字符表示增量值。例如,在秒字段中“5/15”代表从第 5 秒开始,每 15 秒一次。
问号(?)字符和字母 L 字符只有在月内日期和周内日期字段中可用。问号表示这个字段不包含具体值。所以,如果指定月内日期,可以在周内日期字段中插入“?”,表示周内日期值无关紧要。字母 L 字符是 last 的缩写。放在月内日期字段中,表示安排在当月最后一天执行。在周内日期字段中,如果“L”单独存在,就等于“7”,否则代表当月内周内日期的最后一个实例。所以“0L”表示安排在当月的最后一个星期日执行。
在月内日期字段中的字母(W)字符把执行安排在最靠近指定值的工作日。把“1W”放在月内日期字段中,表示把执行安排在当月的第一个工作日内。
井号(#)字符为给定月份指定具体的工作日实例。把“MON#2”放在周内日期字段中,表示把任务安排在当月的第二个星期一。
星号(*)字符是通配字符,表示该字段可以接受任何可能的值。
字段 允许值 允许的特殊字符
秒 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 * * ? 2005" 2005年的每天上午10:15触发
"0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发
"0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发
"0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
"0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
"0 10,44 14 ? 3 WED" 每年三月的星期三的下午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" 每月的第三个星期五上午10:15触发
每天早上6点

0 6 * * *

每两个小时

0 */2 * * *
晚上11点到早上8点之间每两个小时,早上八点

0 23-7/2,8 * * *

每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点

0 11 4 * 1-3
1月1日早上4点

0 4 1 1 *

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值