spring定时任务-quartz.doc_第1页
spring定时任务-quartz.doc_第2页
spring定时任务-quartz.doc_第3页
spring定时任务-quartz.doc_第4页
spring定时任务-quartz.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

spring定时任务-quartz其中period就是一天的微秒数。如果每月1日运行一次,那就复杂了,不知如何配置。因为月份有大、小月之分,每月的微秒数都不一样。而Quartz类库不但有着上述JDK的Timer类库类似的配置,更重要的,它还有着类似于unix的cron服务的配置。因此,在迁移中我们采用了Quartz类库的接口。具体的步骤如下:1 编写业务类,该类继承了org.quartz.Job,主要的逻辑在execute方法中编写2 配置spring的applicationContext.xml文件 2.1 配置任务JobDetailBean 2.2配置触发器 CronTriggerBean 2.3配置调度器 SchedulerFactoryBean3 所需要的jar包: spring.jar,quartz.jar,commons-logging-1.0.4.jar,commons-dbcp-1.2.2.jar,commons-pool-1.3.jar4 把perties放到类路径下以下为一个demo业务类:Java代码 package task; import java.util.Date; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; public class BusinessReport implements org.quartz.Job public void perform() /执行报表统计入口函数 /业务逻辑 System.out.println(开始执行报表的业务逻辑了-现在的时间是-+new Date(); public void execute(JobExecutionContext arg0) throws JobExecutionException perform(); applicationContext.xml文件 !- - 三 perties文件的内容(默认放在类路径下)#=# Configure Main Scheduler Properties #=org.quartz.scheduler.instanceName = DefaultQuartzSchedulerorg.quartz.scheduler.instanceId = AUTOorg.quartz.scheduler.rmi.export = xy = falseorg.quartz.scheduler.wrapJobExecutionInUserTransaction = false#=# Configure ThreadPool #=#org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount = 10org.quartz.threadPool.threadPriority = 5#org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true#=# Configure JobStore #=#org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegateorg.quartz.jobStore.misfireThreshold = 60000#org.quartz.jobStore.useProperties = false#org.quartz.jobStore.tablePrefix = QRTZ_#org.quartz.jobStore.dataSource = myDS#org.quartz.jobStore.isClustered = true#org.quartz.jobStore.clusterCheckinInterval = 15000#=# Configure DataSource#=org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driverorg.quartz.dataSource.myDS.URL = jdbc:mysql:/localhost/testorg.quartz.dataSource.myDS.user = rootorg.quartz.dataSource.myDS.password = rootorg.quartz.dataSource.myDS.maxConnections = 10附:cronExpression表达式解释: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

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论