`

quartz的定时配置表达式

 
阅读更多

ava服务自带了定时服务Timer,不过我在研究spring,所以就使用了quartz,因为spring良好的支持了quartz,使用起来还是相当的简单 

Java代码   收藏代码
  1. <!-- 实现规则服务实时加载的定时服务配置文件 -->  
  2.   
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.          xmlns:aop="http://www.springframework.org/schema/aop"  
  6.          xmlns:tx="http://www.springframework.org/schema/tx"  
  7.          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
  8.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd  
  9.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">  
  10.       
  11.     <bean id="loadObject" class="com.sunyard.rule.global.ContextLoad"/>  
  12.       
  13.     <bean name="jobDetailBean" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
  14.         <property name="targetObject" ref="loadObject"/>  
  15.         <property name="targetMethod" value="load"/>  
  16.     </bean>  
  17.       
  18.     <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">  
  19.        <property name="jobDetail">  
  20.            <ref bean="jobDetailBean" />  
  21.        </property>  
  22.        <!--   
  23.             下面表示每天晚上21点执行  
  24.             配置具体方法见《定时服务配置说明》  
  25.        -->  
  26.        <property name="cronExpression">  
  27.            <value>0 0 21 * * ?</value>  
  28.        </property>  
  29.     </bean>  
  30.       
  31.     <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
  32.         <property name="triggers">  
  33.             <list>  
  34.                 <ref bean="cronTrigger" />  
  35.             </list>  
  36.         </property>  
  37.     </bean>  
  38. </beans>  



id="loadObject"是定时服务类; 
name="jobDetailBean"用来指定定时服务的方法; 
id="cronTrigger"配置定时服务的时间; 
最后一个bean用来设置定时服务队列。 
(解释比较直白) 

下面介绍一下定时服务时间的配置,也可以为以后做备忘: 
表达式意义: 
秒 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 *  

特殊字符说明: 
"*"字符被用来指定所有的值。如:"*"在分钟的字段域里表示"每分钟"。 
"?"字符只在日期域和星期域中使用。它被用来指定"非明确的值"。当你需要通过在这两个域中的一个来指定一些东西的时候,它是有用的。 
月份中的日期和星期中的日期这两个元素时互斥的一起应该通过设置一个问号(?)来表明不想设置那个字段 
"-"字符被用来指定一个范围。如:"10-12"在小时域意味着"10点、11点、12点"。 
","字符被用来指定另外的值。如:"MON,WED,FRI"在星期域里表示"星期一、星期三、星期五". 
"/"字符用来指定具体的增量。如"0/15"在秒中的配置表示"从0秒开始每隔15秒",即"0,15,30,45"。 
如"5/15"在秒中的配置表示"从5秒开始每隔15秒",即"5,20,35,50"。"*/5"和"0/5"是一个效果。 
L是‘last’的省略写法可以表示day-of-month和day-of-week域,但在两个字段中的意思不同, 
例如day-of-month域中表示一个月的最后一天, 如果在day-of-week域表示‘7’或者‘SAT’, 
如果在day-of-week域中前面加上数字,它表示一个月的最后几天,例如‘6L’就表示一个月的最后一个星期五。 

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". 

分享到:
评论

相关推荐

    quartz时间配置表达式生成工具

    quartz时间配置表达式生成工具,通界面配置生成表达式

    quartz的cron表达式

    quartz定时任务的cron表达式配置的详细说明,以及一些具体示例。

    Springboot整合Quartz实现定时任务数据库动态配置

    Springboot整合Quartz实现定时任务数据库动态配置,新增任务、修改cron表达式、暂停任务、恢复任务、删除任务等操作

    Spring2.0+quartz1.8定时执行任务内含Cron表达式生成器

    -- 调用频率设置 每天上午2点和下午5点 cron表达式 --&gt; &lt;bean id="runTime" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt; &lt;value&gt;0 0 2,17 * * ? &lt;!-- 最终启动的配置...

    demo-quartzExpress.rar(quartz表达式

    quartz表达式,可直接解压,使用java本地运行即可查看,编辑表达式,方便定时任务一目了然查看。cron表达式用于配置cronTrigger的实例。cron表达式实际上是由七个子表达式组成。这些表达式之间用空格分隔。

    JAVA定时任务-Quartz应用Demo

    0 0 12 * * ? 每天12点运行 0 15 10 ? * * 每天10:15运行 0 15 10 * * ? 每天10:15运行 0 15 10 * * ? * 每天10:15运行 0 15 10 * * ? 2008 在2008年的每天10:15运行 0 * 14 * * ? 每天14点到15点之间每分钟运行一...

    QUARTZ项目实练

    通过数据表配置service方法类以及cron表达式,实现quartz定时轮询执行

    Quartz-Job-Scheduling-Framework-中文版-V0.9.1.zip

    应用 JobInitializationPlugin 在 quartz_jobs.xml 配置文件中写 Cron 表达式。 第五章. Cron 触发器及相关内容 (第四部分) 内容提要:Cron 表达式 Cookbook,列举了各种 Cron 表达式的写法和意义,有助于更好的...

    基于SpringBoot+Quartz的轻量级分布式定时任务调度系统源码+项目说明+sql数据库.zip

    基于SpringBoot+Quartz的轻量级分布式定时任务调度系统源码+项目说明+sql数据库.zip 主要技术选型 1、后端: - SpringBoot 2.6.11 - Quartz 2.3.2 - Mybatis-Plus 3.5.3.2 - Httpclient 4.5.13 2、前端: - Layui ...

    一个Spring+quartz的例子,希望对大家有帮助

    Spring+quartz 一个简单的 定时任务的例子,希望能对大家的学习有帮助。 最后,附:cronExpression配置说明 字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - *...

    基于 ADF 框架开发的 Quartz 作业调度程序。

    基于 ADF 框架 + Quartz框架 开发的一套界面可操作的作业调度程序。 界面: 1. 输入:支持 cron表达式; 2. 支持定时调用服务; 3. 支持定时调用数据库脚本(存储过程等); 4. 界面可以查看当前运行的后台作业; 5....

    spring定时任务

    spring定时任务 ...-- 关键在配置此表达式 --&gt; &lt;value&gt;0 49 15 * * ? &lt;bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;/beans&gt;

    quartz 包,源文件与 使用说明

    前者用于实现比较简单的定时功能,例如几点开始,几 点结束,隔多长时间执行,共执行多少次等,后者提供了使用表达式来描述定时功能,因此适用于比较复杂的定时描述,例如每个月的最后一个周五,每周的周四 等。...

    demo-quartzExpress.rar

    quartz表达式,可直接解压,使用java本地运行即可查看,编辑表达式,方便定时任务一目了然查看。cron表达式用于配置cronTrigger的实例。cron表达式实际上是由七个子表达式组成。这些表达式之间用空格分隔。

    Java常见面试问题.docx

    9.Quartz的定时调度是怎么实现的?定时调度流程? Wait、notify 实现job类,设置触发器 放到调度器中 start 10.Springboot是怎么整合quartz的? 11.Rides的几种数据类型及应用场景? 12.工作流 activety? 13.禅道...

    基于SpringBoot+Vue构建的轻量级定时任务管理系统,可用于自动化运维,适合个人学习研究,毕业设计,课程设计

    强自定义:支持在线配置定时任务请求类型、请求路径、请求参数、Cron表达式,即时生效; 动态控制:支持动态修改任务状态、启动/停止任务,以及终止运行中任务,即时生效; 执行策略:支持丰富的执行策略,包括:Get...

    Java课程实验 Spring Boot 任务管理(源代码+实验报告)

    将@Scheduled注解与方法一起使用,指定任务执行的时间表达式。 2.使用Spring的TaskScheduler: Spring提供了TaskScheduler接口和相关实现,用于任务调度。使用TaskScheduler,你可以创建计划执行、定期执行或延迟...

    Go定时器cron的使用详解

    我没有用过Linux的cron,但网上说Linux也是可以用crontab -e 命令来配置定时任务。Go语言和Java中都是可以精确到秒的,但是Linux中不行。 cron表达式代表一个时间的集合,使用6个空格分隔的字段表示: 字段名 ...

    OpenAuth.Core后台管理框架 v3.0.1

    6、基于Quartz.Net的定时任务控制,可随时启/停,可视化配置Cron表达式功能 7、基于CodeSmith的代码生成功能,可快速生成带有头/明细结构的页面 8、支持sqlserver、mysql数据库,理论上支持所有数据库 9、集成...

    OpenAuth.Core后台管理框架-.net

    6、基于Quartz.Net的定时任务控制,可随时启/停,可视化配置Cron表达式功能 7、基于CodeSmith的代码生成功能,可快速生成带有头/明细结构的页面 8、支持sqlserver、mysql数据库,理论上支持所有数据库 9、集成...

Global site tag (gtag.js) - Google Analytics