- 浏览: 1573915 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
nich002:
原网站失效了。撸主简单粗暴的复制过来,可读性极差!差评!
Apache配置详解(最好的APACHE配置教程) -
107x:
不错,谢谢!
LINUX下查看文件夹下的文件个数! -
Hypereo:
好你妹,连个格式都没有!
Apache配置详解(最好的APACHE配置教程) -
resteater:
代码排版感觉有点乱!收发信息代码可读性不强!请问第一次发服务器 ...
java socket例子 -
resteater:
代码排版感觉有点乱!收发信息代码可读性不强!请问第一次发服务器 ...
java socket例子
From: www.blogjava.net/javaora/archive/2005/07/20/8070.aspx
定时批处理作业是J2EE企业应用里很重要的一环,用来在晚间进行财务挂账,数据转存,新闻联播等等操作。
而在Spring里,已经很好的集成了Quartz,简单到像配cron一样,在xml文件里面配一下时间就可以自动执行,不需要写一行代码。Spring对Quartz大刀阔斧的简化堪称范例,Quartz项目组也许可以学习一下。
xml 代码
- <bean id="methodInvokingJobDetail"
- class="org.springframework.scheduling.
- quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject"><ref bean="financeDAO"/>property>
- <property name="targetMethod"><value>confirmOrdervalue>property>
- bean>
- <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail">
- <ref bean="methodInvokingJobDetail"/>
- property>
- <property name="cronExpression">
- <value>0 0 6,12,20 * * ?value>
- property>
- bean>
- <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list><ref local="cronTrigger"/>list>
- property>
- bean>
上面这段配置文件规定了在早上6点和晚上8点执行financeDAO对象的confirmOrder()方法.
附:cronExpression配置说明
秒 |
0-59 |
, - * / |
||
分 |
0-59 |
, - * / |
||
小时 |
0-23 |
, - * / |
||
日期 |
1-31 |
, - * ? / L W C |
||
月份 |
1-12 或者 JAN-DEC |
, - * / |
||
星期 |
1-7 或者 SUN-SAT |
, - * ? / L C # |
||
年(可选) |
留空, 1970-2099 |
, - * / |
The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".
“*”字符被用来指定所有的值。如:”*“在分钟的字段域里表示“每分钟”。
The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification.
“?”字符只在日期域和星期域中使用。它被用来指定“非明确的值”。当你需要通过在这两个域中的一个来指定一些东西的时候,它是有用的。看下面的例子你就会明白。
The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
“-”字符被用来指定一个范围。如:“10-12”在小时域意味着“10点、11点、12点”。
The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
“,”字符被用来指定另外的值。如:“MON,WED,FRI”在星期域里表示”星期一、星期三、星期五”.
The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety.
The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
评论
java.lang.Object
|
+--org.quartz.Trigger
|
+--org.quartz.CronTrigger
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable
--------------------------------------------------------------------------------
public class CronTrigger
extends Trigger
A concrete Trigger that is used to fire a JobDetail at given moments in time, defined with Unix 'cron-like' definitions.
For those unfamiliar with "cron", this means being able to create a firing schedule such as: "At 8:00am every Monday through Friday" or "At 1:30am every last Friday of the month".
A "Cron-Expression" is a string comprised of 6 or 7 fields separated by white space. The 6 mandatory and 1 optional fields are as follows:
Field Name Allowed Values Allowed Special Characters
Seconds 0-59 , - * /
Minutes 0-59 , - * /
Hours 0-23 , - * /
Day-of-month 1-31 , - * ? / L W C
Month 1-12 or JAN-DEC , - * /
Day-of-Week 1-7 or SUN-SAT , - * ? / L C #
Year (Optional) empty, 1970-2099 , - * /
The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".
The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification.
The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". You can also specify '/' after the '*' character - in this case '*' is equivalent to having '0' before the '/'.
The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
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".
The legal characters and the names of months and days of the week are not case sensitive.
Here are some full examples:
Expression Meaning
"0 0 12 * * ?" Fire at 12pm (noon) every day
"0 15 10 ? * *" Fire at 10:15am every day
"0 15 10 * * ?" Fire at 10:15am every day
"0 15 10 * * ? *" Fire at 10:15am every day
"0 15 10 * * ? 2005" Fire at 10:15am every day during the year 2005
"0 * 14 * * ?" Fire every minute starting at 2pm and ending at 2:59pm, every day
"0 0/5 14 * * ?" Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day
"0 0/5 14,18 * * ?" Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
"0 0-5 14 * * ?" Fire every minute starting at 2pm and ending at 2:05pm, every day
"0 10,44 14 ? 3 WED" Fire at 2:10pm and at 2:44pm every Wednesday in the month of March. "0 15 10 ? * MON-FRI" Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
"0 15 10 15 * ?" Fire at 10:15am on the 15th day of every month
"0 15 10 L * ?" Fire at 10:15am on the last day of every month
"0 15 10 ? * 6L" Fire at 10:15am on the last Friday of every month
"0 15 10 ? * 6L" Fire at 10:15am on the last Friday of every month
"0 15 10 ? * 6L 2002-2005" Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005
"0 15 10 ? * 6#3" Fire at 10:15am on the third Friday of every month
Pay attention to the effects of '?' and '*' in the day-of-week and day-of-month fields!
NOTES:
Support for the features described for the 'C' character is not complete.
Support for specifying both a day-of-week and a day-of-month value is not complete (you'll need to use the '?' character in on of these fields).
Be careful when setting fire times between mid-night and 1:00 AM - "daylight savings" can cause a skip or a repeat depending on whether the time moves back or jumps forward.
Author:
Sharada Jambula, James House, Contributions from Mads Henderson
See Also:
Trigger, SimpleTrigger, Serialized Form
发表评论
-
JVM问题追查与调优
2012-03-27 14:44 1138JDK的几种分析工具 http://liudaoru ... -
NodeJs相关资料
2011-08-18 14:55 3002NodeJs获取参数: proces ... -
jprofiler追踪问题
2011-08-12 18:20 1046Jprofiler下载页: http://www.ej ... -
Linux服务器性能评估与优化【z】
2011-07-01 10:05 1544来自:http://www.itlearner.com/ ... -
Java 理论与实践: 非阻塞算法简介【z】
2011-03-26 20:39 1282From: http://www.ibm.com/develo ... -
Java Crash问题分析[z]
2011-03-23 14:41 5969参考: http://www.ibm.com/develop ... -
Berkeley DB相关
2010-09-25 22:17 1051为什么要使用Berkeley DB,它适合什么场合应用?Ber ... -
熟悉系统方法总结
2010-07-06 14:26 810了解一个陌生的系统是我们经常碰到的事情,下面总结一下自己的一些 ... -
Java缓存框架 EhCache
2010-07-06 14:09 4723From: http://www.oschina.net/p/ ... -
【nio】使用 ServerSocketChannel 实现的 File 服务器[z]
2010-05-21 17:31 3964From: http://www.java2000.net/p ... -
Memcached命令行管理
2010-03-15 11:18 4483From: http://www.exp2up.com/2 ... -
(转)Resin服务器配置指南
2010-01-21 15:35 3457From:http://blog.21cn.com/super ... -
Flickr架构
2010-01-11 09:52 1266From: http://www.cyask.com/ques ... -
JDK的几种分析工具
2009-12-04 12:13 10902From: http://blog.csdn.net/hant ... -
XMemcached——一个新的开源Java memcached客户端
2009-10-23 09:27 1892From: http://www.infoq.com/cn/ ... -
多线程任务调度学习
2009-10-16 13:58 2299昨天找到一套多线程任务调度的代码,相当的不错,先把思路总结一下 ... -
用HSCALE实现MySQL的数据分布式存储
2009-10-15 12:47 3015From:http://www.ningoo.net/ht ... -
马化腾:搜索、电子商务硬仗一定要坚持打
2009-10-15 12:09 1713From:http://www.techweb.com.c ... -
MySQL分表实现上百万上千万记录分布存储的批量查询设计模式【z】
2009-10-15 09:56 3171From:http://hi.baidu.com/jabber ... -
nginx负载均衡和lvs负载均衡的比较分析【z】
2009-10-13 20:02 1468From:http://www.shouker.com/u ...
相关推荐
总结来说,Quartz是一个功能强大的定时任务管理工具,适用于各种Java应用程序,尤其适合与Spring框架结合使用,以实现灵活、稳定且可扩展的定时任务调度解决方案。其丰富的特性和API,使得开发者可以轻松地处理复杂...
14. **定时任务(Task Scheduling)**:可以使用 Spring 的 @Scheduled 注解来实现定时任务,或者集成 Quartz 进行更复杂的调度。 15. **邮件服务**:通过配置和使用 JavaMailSender 接口,可以方便地发送电子邮件...
然而,由于`webapps`目录下的所有应用程序默认都会被加载,这就导致了应用程序被加载了两次,进而使得Spring配置也被加载了两次,最终导致Quart-Z定时任务执行了两次。 #### 三、解决方案 为了解决这个问题,可以...
本资源包涵盖了Java基础的Job处理、Quartz框架、Spring Scheduling以及Spring与Quartz结合使用时的数据库配置,这些都是Java开发者在实现定时任务时可能会用到的关键技术。 1. **Java基础Job**: 在Java中,我们...
WebQuartz.7z则可能包含了Quartz作业调度的相关配置和类,用于设置和管理定时任务。 综合以上信息,这个博客实例项目展示了一个基于Mybatis和SpringMVC的Web应用开发实例,其中结合了Quartz来实现定时任务。对于...
Java提供了多种实现任务调度的方法,其中最常用的是Quartz和Spring的TaskExecution和TaskScheduling模块。 Quartz是一个开源的作业调度框架,它可以用来创建、调度和执行计划任务。Quartz允许开发者精确地定义任务...
5. **任务调度**:使用Spring Task或者Quartz实现后台任务调度,如定时促销、订单处理等。 6. **分布式缓存**:集成Redis或Memcached,提高数据访问速度,减轻数据库压力。 7. **消息队列**:结合RabbitMQ或Kafka...
这可能涉及到Quartz、Spring Task等任务调度库的使用。 6. **API设计**:系统可能提供RESTful API,方便与其他系统集成。通过源码,我们可以学习API的设计原则和最佳实践。 7. **模块化与插件化**:为了提高系统的...
8. **后台服务器**:系统可能基于Java或.NET搭建后端服务,使用Spring Boot或ASP.NET Core框架,实现业务逻辑处理和数据访问。 9. **通信协议**:系统间通信可能采用RESTful API或SOAP协议,保证数据传输的安全性和...
8. **调度任务**:Quartz或Spring Task可能用于实现定期的任务调度,比如定时更新货物状态、发送提醒通知等。 9. **API接口**:如果系统需要与其他系统集成,可能涉及RESTful API的设计和实现,通过HTTP协议交换...
MyBatis作为DAO层,Druid作为数据库连接池,Redis作为缓存,Solr作为搜索引擎,FastDFS作为分布式文件系统,Nginx作为反向代理服务器,Quartz作为定时任务框架,Tomcat作为Web服务器,使用Maven进行项目管理。...