默认排除每月的一些天
2012-08-07 10:09
218 查看
package com.cavaness.quartzbook.chapter3; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SimpleTrigger; import org.quartz.Trigger; import org.quartz.TriggerUtils; import org.quartz.impl.StdSchedulerFactory; import org.quartz.impl.calendar.AnnualCalendar; import org.quartz.impl.calendar.MonthlyCalendar; import org.quartz.impl.calendar.WeeklyCalendar; /** * 默认排除每月的一些天 * @author Kevin * */ public class Listing_4_9 { private static Log log = LogFactory.getLog(Listing_3_5.class); /** * 创建,启动调度器 * @throws SchedulerException */ public void startScheduler() throws SchedulerException { Scheduler scheduler = null; try { scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (SchedulerException e) { log.error("调度器创建失败!", e); throw e; } try { scheduler.start(); } catch (SchedulerException e) { log.error("调度器启动失败!", e); throw e; } log.info("调度器启动时间:" + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date())); scheduleJob(scheduler, PrintInfoJob.class); } /** * 配置作业,创建触发器 * @param scheduler 调度器 * @param jobClass 作业所在的类 * @throws SchedulerException */ public void scheduleJob(Scheduler scheduler, Class jobClass) throws SchedulerException { MonthlyCalendar monthlyCalendar = new MonthlyCalendar(); // 默认排除每月的一些天 boolean[] excludedDays = new boolean[31];// The array must non-null and of size greater or equal to 31. The 0 index element represents the first day of the month. excludedDays[2] = true; // 第三天排除 excludedDays[4] = true;// 第五天排除 monthlyCalendar.setDaysExcluded(excludedDays); try { scheduler.addCalendar("bankHolidays", monthlyCalendar, true, true); // 两个true分别表示替换和更新原来的monthlyCalendar } catch (SchedulerException e) { log.error("为调度器关联annualCalendar失败!", e); throw e; } Trigger printInfoTrigger = TriggerUtils.makeImmediateTrigger("printInfoTrigger", SimpleTrigger.REPEAT_INDEFINITELY, 10000); printInfoTrigger.setCalendarName("bankHolidays"); // 关联触发器和calendar JobDetail printInfoJobDetail = new JobDetail("printInfoJobDetail", Scheduler.DEFAULT_GROUP, jobClass); try { scheduler.scheduleJob(printInfoJobDetail, printInfoTrigger); // 关联触发器和调度器 } catch (SchedulerException e) { log.error("关联触发器printInfoTrigger和调度器scheduler失败!", e); throw e; } } public static void main(String[] args) throws SchedulerException { Listing_4_9 listing_4_9 = new Listing_4_9(); listing_4_9.startScheduler(); } }
相关文章推荐
- [4750G] 【ubuntu分享帖】acer 4750G ubuntu安装后的一些设置 (ADSL,软件源--最好使用ubuntu默认的源)
- jsp一些异常总结(转自校内--2008-11-26 20:01 (分类:默认分类))
- DNS和ARP的工作原理、以及一些网络故障排除
- 编程拾遗:集合类型的函数,返回值,如果没有,就返回默认集合new,或者 default(T)好一些。
- 【iOS7的一些总结】6、采用NSUSerDefault保存用户默认数据
- firefox代理服务器,排除地址设置的一些经验
- 排除一些字
- 浏览器默认样式的一些看法(User Agent Stylesheet)
- 不能联网的一些原因及测试排除
- visual studio建MFC应用程序成功了,但是项目内无一些默认的工程文件生成
- tar打包时排除一些文件或者目录
- 表里有一些默认的数据 用什么方法生成一条一条的insert into语句
- ABAP和Java里关于DEFAULT(默认)机制的一些语言特性
- dubbo的一些默认变量
- 修改Bootstrap的一些默认样式
- 排除“计算机-默认 权限设置未将 COM 服务器应用程序”的错误
- [Extjs6] Ext.data.Store Gridpanel默认选中一些记录
- c语言一些默认i_ __int64
- 登录后默认转向登陆前的页面排除外部网站页面
- 确保你的备份恰到好处 Ubuntu桌面版的默认工具:dejá-dup仅被设置为默认备份你的home目录,因此它遗漏一些你在需要将系统恢复到有序的工作状态时的重要部分。让我们试想一下你的系统由以下三个部