Quartz Scheduler(2.2.1) - hello world
简单示例
1. maven 依赖
<dependencies>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency> <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
2. quarzt.properties(可选)
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
3. Job
package com.huey.hello.quartz; import java.util.Date; import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import com.huey.hello.quartz.utils.DateUtils; public class HelloJob implements Job { /**
* 实 现 org.quartz.Job 接口,并实现 execute 方法,在此方法执行业务逻辑
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
Date fireTime = context.getFireTime();
System.out.println("Hello Quartz Scheduler! " + DateUtils.dateToStr(fireTime));
} }
4. Simple Code
package com.huey.hello.quartz; import org.quartz.CronExpression;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory; public class MainApp { public static void main(String[] args) throws Exception { // 创建 SchedulerFactory 并获取 Scheduler 对象实例
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = schedulerFactory.getScheduler(); // 通过 JobBuilder 创建 JobDetail 对象实例
JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
.withIdentity("helloJob", Scheduler.DEFAULT_GROUP)
.build(); // 通过 TriggerBuilder 创建 Trigger 对象实例,设置每 5 秒调度一次任务
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("helloTrigger", Scheduler.DEFAULT_GROUP)
.withSchedule(CronScheduleBuilder.cronSchedule(new CronExpression("0/5 * * * * ?")))
.build(); // 排定任务
scheduler.scheduleJob(jobDetail, trigger); // 启动调度器
scheduler.start();
//
Thread.sleep(20L * 1000L);
// 关闭调度器
scheduler.shutdown(true); } }
Key Interface
Scheduler - the main API for interacting with the Scheduler.
Job - an interface to be implemented by components that you want the Scheduler to execute.
JobDetail - used to define instances of Jobs.
Trigger - a component that defines the schedule upon which a given Job will be executed.
JobBuilder - used to define/build JobDetail instances, which define instances of Jobs.
TriggerBuilder - used to define/build Trigger instances
SimpleTrigger - it is handy if you need 'one-shot' execution (just single execution of a job at a given moment in time), or if you need to fire a job at a given time, and have it repeat N times, with a delay of T between executions.
CronTrigger - it is useful if you wish to have triggering based on calendar-like schedules such as "every Friday, at noon" or "at 10:15 on the 10th day of every month."
Quartz Scheduler(2.2.1) - hello world的更多相关文章
- spring集成quartz scheduler
创建项目 有两种创建quart配置作业 1.使用MethodInvokingJobDetailFactoryBean Quartz Scheduler 配置作业(MethodInvokingJobD ...
- Table of Contents - Quartz Scheduler
Getting Started Hello World Integration with Spring Quartz Scheduler Developer Guide Usage of JobDat ...
- Quartz Scheduler(2.2.1) - Working with JobStores
About Job Stores JobStores are responsible for keeping track of all the work data you give to the sc ...
- Quartz Scheduler 开发指南(1)
Quartz Scheduler 开发指南(1) 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 实例化调度程序( ...
- 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例
参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...
- 整合shiro出现【Correct the classpath of your application so that it contains a single, compatible version of org.quartz.Scheduler】
跑的时候出现错误: Description: An attempt was made to call the method org.quartz.Scheduler.getListenerManage ...
- Quartz Scheduler(2.2.1) - Integration with Spring
1. maven 依赖: <properties> <spring.version>3.2.3.RELEASE</spring.version> <quart ...
- Quartz Scheduler(2.2.1) - Usage of JobDataMap
The JobDataMap can be used to hold any amount of (serializable) data objects which you wish to have ...
- Quartz Scheduler(2.2.1) - Usage of Calendars
Quartz Calendar objects (not java.util.Calendar objects) can be associated with triggers at the time ...
随机推荐
- 部署 instance 到 OVS flat network - 每天5分钟玩转 OpenStack(135)
上一节创建了 OVS flat network,今天我们部署 instance 并验证 flat 网络的连通性. launch 新的 instance "cirros-vm1",网 ...
- TypeScript学习笔记(二):基本数据类型及数据转换
数据类型 我们来看看TypeScript中的基本数据类型都有哪些. boolean 布尔值,支持true和false. var isDone: boolean = false; 默认为undefine ...
- union all 简单用法
select Y.ID,sum(cast(Y.m as int)) as hefrom(select top 10 a.ID,a.AlarmSource as m from dbo.AlarmInfo ...
- Cocos2d-x——Cocos2d-x 屏幕适配新解【转载】
Cocos2d-x 屏幕适配新解 本文出自[无间落叶](转载请保留出处):http://blog.leafsoar.com/archives/2013/05-10-19.html 为了适应移动终端的各 ...
- codeforces Gym 100500H H. ICPC Quest 水题
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题
Problem I. TV ShowTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- delphi array应用 DayOfWeek星期几判断
//array应用 DayOfWeek星期几判断 procedure TForm1.Button1Click(Sender: TObject);var days:array[1..7] of s ...
- delphi 中DLL的建立
Dll的创建与调用 File ->New->Other->Dll Wizard DLL的创建 //可以将本代码复制粘贴到项目中 library Project1; uses S ...
- [IOS]自定义长触屏事件
写一个Demo来自定义一个长触屏事件,自定义长按手势. 实现步骤: 1.创建一个自定义手势类,命名为LongPressGestureRecognizer,在创建的时候继承UIGestureRecogn ...
- 将Uploads文件夹移到其它地方
1.在创建目录 cd /mnt/xvdb mkdir qingtong 2.复制目录和权限 cp -rp /Uploads/ ./ -r 包括目录 p权限 3.创建软链接 ln -s /mnt/xvd ...