Quartz Scheduler(2.2.1) - Usage of Calendars
Quartz Calendar objects (not java.util.Calendar objects) can be associated with triggers at the time the trigger is defined and stored in the scheduler.
Calendars are useful for excluding blocks of time from the trigger's firing schedule. For instance, you could create a trigger that fires a job every weekday at 9:30 am, but then add a Calendar that excludes all of the business's holidays.
Calendar's can be any serializable object that implements the Calendar interface {shown below).
package org.quartz;
public interface Calendar {
public boolean isTimeIncluded(long timeStamp);
public long getNextIncludedTime(long timeStamp);
}
Notice that the parameters to these methods are of the long type. These are timestamps in millisecond format. This means that calendars can 'block out' sections of time as narrow as a millisecond. Most likely, you'll be interested in 'blocking-out' entire days. As a convenience, Quartz includes the class org.quartz.impl.HolidayCalendar, which does just that.
Calendars must be instantiated and registered with the scheduler via the addCalendar(..) method. If you use HolidayCalendar, after instantiating it, you should use its addExcludedDate(Date date) method in order to populate it with the days you wish to have excluded from scheduling. The same calendar instance can be used with multiple triggers as shown in the example below:
HolidayCalendar cal = new HolidayCalendar();
cal.addExcludedDate( someDate );
cal.addExcludedDate( someOtherDate );
sched.addCalendar("myHolidays", cal, false);
Trigger t = newTrigger()
.withIdentity("myTrigger")
.forJob("myJob")
.withSchedule(dailyAtHourAndMinute(9, 30)) // execute job daily at 9:30
.modifiedByCalendar("myHolidays") // but not on holidays
.build();
// .. schedule job with trigger
Trigger t2 = newTrigger()
.withIdentity("myTrigger2")
.forJob("myJob2")
.withSchedule(dailyAtHourAndMinute(11, 30)) // execute job daily at 11:30
.modifiedByCalendar("myHolidays") // but not on holidays
.build();
// .. schedule job with trigger2
The code above creates two triggers, each scheduled to fire daily. However, any of the firings that would have occurred during the period excluded by the calendar will be skipped.
The org.quartz.impl.calendar package provides a number of Calendar implementations that may suit your needs.
Quartz Scheduler(2.2.1) - Usage of Calendars的更多相关文章
- 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 SimpleTrigger
SimpleTrigger should meet your scheduling needs if you need to have a job execute exactly once at a ...
- Quartz Scheduler(2.2.1) - Usage of CronTriggers
Cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerfu ...
- 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 ...
- spring集成quartz scheduler
创建项目 有两种创建quart配置作业 1.使用MethodInvokingJobDetailFactoryBean Quartz Scheduler 配置作业(MethodInvokingJobD ...
- Quartz Scheduler(2.2.1) - hello world
简单示例 1. maven 依赖 <dependencies> <dependency> <groupId>org.quartz-scheduler</gro ...
- 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 进行任务调度. ...
随机推荐
- WebForm 回传后如何保持页面的滚动位置
转载自 http://www.cnblogs.com/renjuwht/archive/2009/06/17/1505000.html 默认情况下,ASP.NET页面回传到服务器后,页面会跳回顶部.对 ...
- java中关于类的封装与继承,this、super关键字的使用
原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/5454849.html. this关键字: this代表当前对象,它有以下几种用途: 1.本类 ...
- UVa10050 Hartals
// 题意:输入n和p个整数H[i],其中H[i]表示每H[i]天会有一次活动(但周五周六除外).输出前n天中有多少天有活动.模拟从周日开始. #include<cstdio> #in ...
- 启用MySQL查询缓存
启用MySQL查询缓存能够极大地减低数据库server的CPU使用率,实际使用情况是:开启前CPU使用率120%左右,开启后降到了10%. 查看查询缓存情况: mysql> show varia ...
- Quart 2D 绘制图形简单总结
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGConte ...
- 【ZZ】Java : 一个帝国的诞生 & 假如时光能够倒流, 我会这么学习Java
Java : 一个帝国的诞生 http://dy.qq.com/article.htm?id=20160523A06XFS00 写的很有意思,一下子了解了JAVA的历史. 假如时光能够倒流, 我会这么 ...
- java_闭包和回调实现一边按键盘一边演讲
package ming; interface Teachable { void work(); } class Programer { private String name; public Str ...
- [小技巧]兼容IE6的纯CSS背景半透明文字不透明
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JavaFX(一)窗口跳转
笔者此处不讲JavaFX的基础API,只针对笔者工作时遇到的问题进行记录与总结. 零基础的网友可以访问http://www.javafxchina.net/blog/docs/tutorial1/进行 ...
- cocos2d-x混合BlendFunc的使用
1.什么是混合模式 “混合”是指两种颜色的叠加方式.在新图片将要渲染画到屏幕上的时候,将用在新图片中的红.绿.蓝和透明度信息,与屏幕上已经存在的图片颜色信息相融合. 说的具体一点,就是把某一像素位置上 ...