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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Table of Contents - Quartz Scheduler

    Getting Started Hello World Integration with Spring Quartz Scheduler Developer Guide Usage of JobDat ...

  5. 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 ...

  6. spring集成quartz scheduler

    创建项目 有两种创建quart配置作业 1.使用MethodInvokingJobDetailFactoryBean  Quartz Scheduler 配置作业(MethodInvokingJobD ...

  7. Quartz Scheduler(2.2.1) - hello world

    简单示例 1. maven 依赖 <dependencies> <dependency> <groupId>org.quartz-scheduler</gro ...

  8. Quartz Scheduler 开发指南(1)

    Quartz Scheduler 开发指南(1) 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 实例化调度程序( ...

  9. 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例

    参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...

随机推荐

  1. poj 3693 Maximum repetition substring (后缀数组)

    其实是论文题.. 题意:求一个字符串中,能由单位串repeat得到的子串中,单位串重复次数最多的子串.若有多个重复次数相同的,输出字典序最小的那个. 解题思路:其实跟论文差不多,我看了很久没看懂,后来 ...

  2. myeclipse内存配置

    配置文件路径:D:\work\myeclipse\MyEclipse for Spring 10\myeclipseforspring.ini 替换以下内容即可 -vmargs-Xmx768m-XX: ...

  3. jquery页面加载的时候加载函数

    http://blog.csdn.net/tjcyjd/article/details/6713474 jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看 ...

  4. C#客户端链接网页需要用到的WebClient

    WebClient 类提供向 URI 标识的任何本地.Intranet 或 Internet 资源发送数据以及从这些资源接收数据的公共方法. WebClient 类使用 WebRequest 类提供对 ...

  5. 【不积跬步,无以致千里】linux下如何查看自己的外网IP

    局域网的服务器是通过ADSL路由器连接外网的,但ADSL是从ISP运营商那儿通过动态获得IP的,那么我怎么知道自己的外网地址是多少呢?今天得到几个办法:curl -s http://whatismyi ...

  6. error log

    04-29 18:18:17.295 6903-6913/? I/art: Debugger is no longer active 04-29 18:18:17.473 157-157/? I/DE ...

  7. 关于php一句话免杀的分析<转载>

    一开始想这样:   <?php $_GET['ts7']($_POST['cmd']);?> 客户端用菜刀,密码cmd,url为test.php?ts7=assert   这个应该算没有什 ...

  8. Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp

    C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. 对CAB文件进行数字签名

    对CAB文件进行数字签名 传说中数字签名之后就能够不出现提示而自己主动下载,所以也试试: 在\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin 中间有三个小 ...

  10. iOS开发——语法篇&swift经典语法总结

    swift经典语法总结 1:函数 1.1 func funcNmae()->(){} 这样就定义了一个函数,它的参数为空,返回值为空,如果有参数和返回值直接写在两个括号里就可以了 1.2 参数需 ...