- 浏览: 172666 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (87)
- Android (7)
- J2EE (34)
- JavaScript (6)
- CSS (1)
- Scala (0)
- WEB (5)
- Ruby (1)
- J2EE Netbeans JDK (1)
- Maven (2)
- AndroidMenuTest (0)
- ExtJS (1)
- MyBatis (4)
- iBatis (3)
- Quartz (1)
- JavaABC (3)
- HTML (1)
- JQuery (2)
- mysql (3)
- Linux (2)
- windows (1)
- ant (2)
- jboss (1)
- eclipse (1)
- junit (1)
- nginx (1)
- Google (0)
- git (2)
- python (1)
- kafka (1)
- sqlserver (1)
- jdk8+ (1)
Quartz 官网 http://quartz-scheduler.org
Quartz各版本下载地址http://quartz-scheduler.org/downloads/catalog
Quartz官方文档地址http://www.quartz-scheduler.org/documentation
Release Notes:
Quartz 2.0.2, 5/27/2011
Quartz 1.8.5, 4/12/2011
Quartz 1.7.3, 2/23/2010
Quartz 1.6.6, 11/2/2009
Quartz 1.5.2, 3/3/2006
Quartz 1.4.5, 3/13/2005
搜了一下网络上的很多有关Quartz的中文版的东西还都是1.6版本前的,看来近两年大家使用Quartz的不多啊。但是项目需求需要我学习一下,还是用最新的2.0.2吧。
包里面有15个例子,我慢慢看吧,估计这十五个例子看完就基本掌握了Quartz了吧。
按照官方的Quick Start:http://www.quartz-scheduler.org/documentation/quartz-2.1.x/quick-start
首先看看quartz.properties的配置文件吧,不过貌似只有例10,11,14用了。
先上一个例1吧:
Job类,你要执行的Job
真正的定时器在这里:
新老版本的改动还是挺大的
JobDetail jobDetail = new JobDetail("jobDetail-s1", "jobDetailGroup-s1", HelloJob.class);
新版本的JobDetail也改为接口类型了。
JobDetail job = newJob(HelloJob.class)
.withIdentity("job1", "group1")
.build();
Quartz各版本下载地址http://quartz-scheduler.org/downloads/catalog
Quartz官方文档地址http://www.quartz-scheduler.org/documentation
Release Notes:
Quartz 2.0.2, 5/27/2011
Quartz 1.8.5, 4/12/2011
Quartz 1.7.3, 2/23/2010
Quartz 1.6.6, 11/2/2009
Quartz 1.5.2, 3/3/2006
Quartz 1.4.5, 3/13/2005
搜了一下网络上的很多有关Quartz的中文版的东西还都是1.6版本前的,看来近两年大家使用Quartz的不多啊。但是项目需求需要我学习一下,还是用最新的2.0.2吧。
包里面有15个例子,我慢慢看吧,估计这十五个例子看完就基本掌握了Quartz了吧。
按照官方的Quick Start:http://www.quartz-scheduler.org/documentation/quartz-2.1.x/quick-start
首先看看quartz.properties的配置文件吧,不过貌似只有例10,11,14用了。
org.quartz.scheduler.instanceName: PriorityExampleScheduler # Set thread count to 1 to force Triggers scheduled for the same time to # to be ordered by priority. org.quartz.threadPool.threadCount: 1 org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
先上一个例1吧:
Job类,你要执行的Job
package com.oneregal.util; import java.util.Date; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; /** * @author yiranrenxiaoyao */ public class HelloJob implements Job { private static Logger _log = LoggerFactory.getLogger(HelloJob.class); public HelloJob() { } /** * * @throws JobExecutionException * if there is an exception while executing the job. */ public void execute(JobExecutionContext context) throws JobExecutionException { // Say Hello to the World and display the date/time _log.info("Hello World! - " + new Date()); JobKey jobKey = context.getJobDetail().getKey(); JobDataMap dataMap = context.getJobDetail().getJobDataMap(); String jobSays = dataMap.getString("jobSays"); float myFloatValue = dataMap.getFloat("myFloatValue"); System.out.println("JobSays:" + jobSays); } }
真正的定时器在这里:
package com.oneregal.util; import static org.quartz.JobBuilder.newJob; import static org.quartz.TriggerBuilder.newTrigger; import static org.quartz.DateBuilder.*; import java.util.Date; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author yiranrenxiaoyao */ public class SimpleExample { public void run() throws Exception { Logger log = LoggerFactory.getLogger(SimpleExample.class); log.info("------- Initializing ----------------------"); // First we must get a reference to a scheduler SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); log.info("------- Initialization Complete -----------"); // computer a time that is on the next round minute Date runTime = evenMinuteDate(new Date()); log.info("------- Scheduling Job -------------------"); // define the job and tie it to our HelloJob class //You will typically want to use a static import of all of its methods, //in order to have the DSL-feel within your code. //以上是官方文档里面的解释为什么用import static,可以让你DSL-feel, //这feel其实我觉得到不太习惯呢,还是更喜欢JobBuilder.newJob(HelloJob.class) JobDetail job = newJob(HelloJob.class) .withIdentity("job1", "group1") .usingJobData("jobSays", "Hello Quartz!") .usingJobData("myFloatValue", 3.1415926f) .build(); //Tutorials里面有.usingJobData("myStateData", new ArrayList()),可是我看API里面 //Value属性只有Boolean,Double,Float,Integer,Long,没看到Object或者List //但是usingJobData(JobDataMap)这个就实用多了,类似Java的Map可以随意往里面塞数据了 //JobDataMap dMap = new JobDataMap();dMap.put(key,value); // Trigger the job to run on the next round minute Trigger trigger = newTrigger() .withIdentity("trigger1", "group1") .startAt(runTime) .build(); // Tell quartz to schedule the job using our trigger sched.scheduleJob(job, trigger); log.info(job.getKey() + " will run at: " + runTime); // Start up the scheduler (nothing can actually run until the // scheduler has been started) sched.start(); log.info("------- Started Scheduler -----------------"); // wait long enough so that the scheduler as an opportunity to // run the job! log.info("------- Waiting 65 seconds... -------------"); try { // wait 65 seconds to show job Thread.sleep(65L * 1000L); // executing... } catch (Exception e) { } // shut down the scheduler log.info("------- Shutting Down ---------------------"); sched.shutdown(true); log.info("------- Shutdown Complete -----------------"); } public static void main(String[] args) throws Exception { SimpleExample example = new SimpleExample(); example.run(); } }
新老版本的改动还是挺大的
JobDetail jobDetail = new JobDetail("jobDetail-s1", "jobDetailGroup-s1", HelloJob.class);
新版本的JobDetail也改为接口类型了。
JobDetail job = newJob(HelloJob.class)
.withIdentity("job1", "group1")
.build();
发表评论
-
日志过滤小工具
2020-01-06 20:15 3951.从全量日志中截断部 ... -
GC参考手册
2017-11-09 14:12 498英文版原文:GC Tuning: In Practice 垃圾 ... -
IDENTITY_INSERT 设置为 OFF 时无法指定插入自增ID
2017-02-15 16:10 635IDENTITY_INSERT 设置为 OFF 时,无法指定I ... -
运行时Exception:Wrong return type in function
2015-11-17 21:31 1501D:\Soft\jdk1.7.0_79\bin\java ... -
Java中的常量:如何避免反模式
2015-10-20 20:41 427参考http://www.importnew.com/1670 ... -
java Socket通信小栗子
2015-09-14 09:25 580server端: package com.test.soc ... -
MyBatis 自动生成xml文件
2015-03-12 11:22 3730package com.test.mybatis; ... -
Java mail test
2015-02-12 11:03 1238mail局域网Exchange服务器测试代码,仅限发送到dom ... -
Java Concurrency / Multithreading Tutorial
2014-10-28 09:35 678Java Concurrency / Multithreadi ... -
Comparison method violates its general contract!
2014-10-22 17:24 929jdk1.6升级到1.7后Comparator有null的参数 ... -
JDK1.7 不兼容compare方法
2014-10-21 16:20 741java.lang.IllegalArgumentExcept ... -
Unknown Source的出现及解决
2014-06-18 10:03 898http://www.2cto.com/kf/201103/8 ... -
ApplicationDeadlockException
2014-06-16 15:39 765参考 : How to avoid huge transact ... -
Java Date相关处理
2014-02-26 14:35 5851.获取UTC时间: Calendar c ... -
Error listenerStart
2013-12-11 19:25 700INFO: Deploying web applicati ... -
Error configuring application listener of class org.springframework.web.context.
2013-12-07 18:54 38148如果Eclipse的BuildPath里面不缺jar包并且在 ... -
iReport字体报错“JRFontNotFoundException”
2013-10-11 11:08 12702net.sf.jasperreports.engine.uti ... -
Eclipse里Jboss的配置
2013-07-15 17:41 9321.\WorkSpace\.metadata\.plugins ... -
Ant安装使用入门
2013-07-04 14:03 550下载Ant之后,增加环境变量1.ANT_HOME=xx/xx/ ... -
javaSystem获取系统信息
2013-03-27 16:30 790public static void main(Strin ...
相关推荐
内含: quartz-1.5.2.zip 定时器Quartz及使用说明 Quartz的API
Quartz是java的开源定时器,使用十分广泛,附件是开源定时器Quartz的源文件
Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2SE应用程序相结合也可以单独使用。Quartz可以用来创建...Jobs可以做成标准的Java组件或 EJBs。Quartz的最新版本为Quartz 2.3.0。
Spring 中的 Quartz 配置-Spring 定时器-java 定时器 在 Spring 框架中,Quartz 是一个非常流行的开源作业调度器,可以实现任务的定时执行。在本篇文章中,我们将讨论如何在 Spring 中配置 Quartz,以实现 Java ...
JAVA定时器是一种基于Quartz框架的任务调度器,用于在指定的时间执行特定的任务。在 Spring 框架中,JAVA定时器可以与Quartz框架集成,实现自动执行任务的功能。 1. JAVA定时器的基本概念 JAVA定时器是基于Quartz...
Spring Quartz 定时器示例(Java工程版),欢迎下载。
spring定时器代码。解决多次执行问题。包含quartz-all.jar包。 说明很详细。希望能帮上哪位朋友。
SSM定时器quartz练习,可以实际运行,直接运行MAIN就行.简单
有助于你快速的查找您要使用的类对象及其方法。
idea 使用spring自带的定时器quartz 使用的c3p0 v0.95.2所包含的jar 亲测可用
Spring Quartz 定时器示例(Web工程版),欢迎下载。
spring 定时器 quartz
当服务启动时自动调用某一个类中的方法,相隔一段时间后再重复执行该方法(相隔时间在配置文件中自己配置,此例直接运行即可)
动态定时器quartz,可以用来动态跑批等执行任务!放在别的框架里面也能使用,主要看代码!
完成定时任务所需jar包,希望对大家有帮助
NULL 博文链接:https://ap0406708.iteye.com/blog/588695
定时器(Quartz)使用说明 Quartz开发指南 本文目前主要包括如下几个部分: Quartz功能简介:介绍Quartz的特点及概念。 使用Quartz的常见问题:很多用户在使用过程中遇到常见问题的解答。 快速开始:让读者尽快掌握...
本篇文章主要介绍了java Quartz定时器任务与Spring task定时的几种实现方法的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
定时器的配置文件(两种方式:springmvc自带定时,Quartz与spring结合的定时)