atititt.java定时任务框架选型Spring Quartz 注解总结
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了atititt.java定时任务框架选型Spring Quartz 注解总结,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5337字,纯文字阅读大概需要8分钟。
内容图文
![atititt.java定时任务框架选型Spring Quartz 注解总结](/upload/InfoBanner/zyjiaocheng/1069/1d89bc86e535473fb0a471f1c1f793a2.jpg)
atititt.java定时任务框架选型Spring Quartz 总结
1. 。Spring Quartz (ati recomm) 1
2.2. 添加xsi:schemaLocation valide 2
2.3. 我们的task任务扫描注解in spr.xml 2
6. 2) ServletContextListener 4
7. org.springframework.scheduling.timer.ScheduledTimerTask 5
1. 。
Spring Quartz (ati recomm)
· Spring的scheduling。
quartz包中对Quartz的框架进行封装,使得开发时不用写不论什么Quartz和Spring的代码就能够实现定时任务。Spring通过 JobDetailBean,MethodInvokingJobDetailFactoryBean实现Job的定义。后者更加使用,仅仅需指定要执行的 类,和该类中执行的方法就可以,Spring将自己主动生成符合Quartz要求的JobDetail。比如:
· .web.xml :
· 增加
· <listener>
· <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
· </listener>
Spring3中加强了注解的使用,当中计划任务也得到了增强。如今创建一个计划任务仅仅须要两步就完毕了:
作者:: 老哇的爪子 Attilax 艾龙。 EMAIL:1466519819@qq.com
转载请注明来源: http://blog.csdn.net/attilax
2.
3. Spring Quartz详细配置
3.1. 添加context,task命名空间xml:
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:task = "http://www.springframework.org/schema/task"
3.2. 添加xsi:schemaLocation valide
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
3.3. 我们的task任务扫描注解in spr.xml
<!-- o723 ati task add -->
< task:annotation-driven />
< context:annotation-config />
< context:component-scan base-package="com.attilax.time.**"/>
< bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<!-- iha ssh recomm
<task:executor id="executor" pool-size="5" />
<task:scheduler id="scheduler" pool-size="10" />
<task:annotation-driven executor="executor" scheduler="scheduler" />
-->
</ beans >
3.4. 设置执行方法
*/ @Component
public class sysncTimeX {
public static Logger logger = Logger . getLogger ( "AtiTimerSyncer" ) ;
@Scheduled ( cron = "0 0 8 * * ?" )
private static void sync () {
Date date = DateUtil . getDateFrmNet () ;
dateTimeX . setSystime ( date ) ;
logger . info ( "--o7k1 sync time:ok" ) ;
}
///@Scheduled(fixedDelay=2000)//每2秒运行一次
3.5. 设置输出日志
#---------- ati o7k..
log4j.logger.AtiTimerSyncer = info,AtiTimerSyncerAppender
log4j.appender.AtiTimerSyncerAppender = org.apache.log4j.DailyRollingFileAppender
log4j.appender.AtiTimerSyncerAppender.Encoding = UTF-8
log4j.appender.AtiTimerSyncerAppender.File = logs/AtiTimerSyncer.log
log4j.appender.AtiTimerSyncerAppender.MaxFileSize = 20MB
log4j.appender.AtiTimerSyncerAppender.Threshold = debug
log4j.appender.AtiTimerSyncerAppender.ImmediateFlush = true
log4j.appender.AtiTimerSyncerAppender.DatePattern = ‘_‘ yyyy -MM- dd ‘.log‘
log4j.appender.AtiTimerSyncerAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.AtiTimerSyncerAppender.layout.ConversionPattern = %-4r %-5p [%d{ yyyy -MM- dd HH:mm:ss}] %m %p [ thrd :%t] loger :%c (%C.%M.%L) %n
log4j.appender.AtiTimerSyncerAppender.MaxBackupIndex = 10
#-----------------
4. 执行測试sprX走ok兰.
public static void main ( String [] args ) {
// attilax 老哇的爪子 ml38 o7k
// sync();
System . out . println ( SpringUtil . getBean ( "sysncTimeX" )) ;
}
5. Quartz Scheduler,定时任务
Quartz是一个作业调度系统(a job scheduling system),负责在约定的时间到达时执行(或通知)其它软件控制。是一个Java的定时任务框架,使用它能够方便的实现计划任务,即在某个时间或每隔 一定时间执行一个任务。Quartz的核心是Job/JobDetail,Trigger和Scheduler。
6. java.util.Timer
1)
这种方法应该是最经常使用的。只是这种方法须要手工启动你的任务:
假设要运行一些简单的定时器任务,无须做复杂的控制。也无须保存状态,那么能够考虑使用JDK 入门级的定期器Timer来运行反复任务。
2)
7. 2) ServletContextListener
这种方法在web容器环境比較方便,这样,在web server启动后就能够
自己主动执行该任务,不须要手工操作。
8. org.springframework.scheduling.timer.ScheduledTimerTask
3)
假设你用spring。那么你不须要写Timer类了,在schedulingContext-timer
.xml中增加以下的内容就能够了:
9. problem
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException : Line 115 in XML document from file [D:\workspace\vodx\WebRoot\WEB-INF\classes\applicationContext-common.xml] is invalid; nested exception is org.xml.sax.SAXParseException : cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘task:annotation-driven‘.
10. Cron表达式
被用来配置CronTrigger实例。 Cron表达式是一个由 7个子表达式组成的字
符串。
每一个子表达式都描写叙述了一个单独的日程细节。这些子表达式用空格分隔。分别表示:
1. Seconds 秒
2. Minutes 分钟
3. Hours 小时
4. Day-of-Month 月中的天
5. Month 月
6. Day-of-Week 周中的天
7. Year (optional field) 年(可选的域)
剩下的就是corn表达式了、详细使用以及參数请百度google、
【秒】 【分】 【时】 【日】 【月】 【周】 【年】
以下仅仅例出几个式子
CRON表达式 含义
"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触发
11. 參考
JAVA定时运行任务的三种方法 - gembin - BlogJava.htm
Quartz使用-入门使用(java定时任务实现) - lotusyangjun的专栏 - 博客频道 - CSDN.NET.htm
java定时任务管理 - 塵风的blog - ITeye技术站点.htm
quartz 框架定时任务。使用spring @Scheduled注解运行定时任务 - 萧若寒 - 博客频道 - CSDN.NET.htm
quartz 框架定时任务,使用spring @Scheduled注解运行定时任务 - 萧若寒 - 博客频道 - CSDN.NET.htm
原文:http://www.cnblogs.com/cynchanpin/p/6789663.html
内容总结
以上是互联网集市为您收集整理的atititt.java定时任务框架选型Spring Quartz 注解总结全部内容,希望文章能够帮你解决atititt.java定时任务框架选型Spring Quartz 注解总结所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。