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 ...
随机推荐
- 应用完全启动后, Spring执行自定义初始化
项目中做敏感词过滤, 因为前台ajax校验要走service ,而后台统一过滤器要走interceptor , 所以把检查器提到一个工具类(HeXieWordFinder)里 这个工具类理应缓存数据库 ...
- oracle备份恢复之rman恢复到异机
注意事项: 1 此处实验环境为同平台,同字节序,同版本,源机器和目标机器相同的目录结构. 2 目标机器只需要安装oracle数据库软件即可. 3 第一次利用备份恢复测试环境,之后从源机器拷贝备份到目标 ...
- android SoundPool播放音效
MediaPlayer的缺点: 资源占用量高,延时时间较长 不支持多个音效同一时候播放 SoundPool主要用于播放一些较短的声音片段,CPU资源占用率低和反应延时小,还支持自行色设置声音的品质,音 ...
- UOJ 08 Quine 是在下输了
#8. Quine Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/8 Description 写一个程序,使其能 ...
- Codeforces Gym 100733A Shitália 计算几何
ShitáliaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- HDU 4593 H - Robot 水题
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HTTP协议报文、工作原理及Java中的HTTP通信技术详解
一.web及网络基础 1.HTTP的历史 1.1.HTTP的概念: HTTP(Hyper Text Transfer Protocol ...
- yii2 rbac 设计
tbl_auth_item 根据type存储认证项目...role.task.operation 游客... 不能操作任何模块 普通用户 ..biz_rule..需要登录 只有这里返回true,才能进 ...
- Ruby on Rails Tutorial 第一章 之 Heroku部署
1.目的:用Heroku将开发环境部署到生产环境中.Heroku专门用于部署Rails和其他Web应用,部署Rails应用的过程非常简单——只要源码纳入Git版本控制系统就好. 2.搭建Heroku部 ...
- C#_Fileuploadify_notMvc
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.c ...