Quartz1.8.5例子(八)
/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/ package org.quartz.examples.example8; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; /**
* <p>
* This is just a simple job that gets fired off many times by example 1
* </p>
*
* @author Bill Kratzer
*/
public class SimpleJob implements Job { private static Logger _log = LoggerFactory.getLogger(SimpleJob.class); /**
* Empty constructor for job initilization
*/
public SimpleJob() {
} /**
* <p>
* Called by the <code>{@link org.quartz.Scheduler}</code> when a
* <code>{@link org.quartz.Trigger}</code> fires that is associated with
* the <code>Job</code>.
* </p>
*
* @throws JobExecutionException
* if there is an exception while executing the job.
*/
public void execute(JobExecutionContext context)
throws JobExecutionException { // This job simply prints out its job name and the
// date and time that it is running
String jobName = context.getJobDetail().getFullName();
_log.info("SimpleJob says: " + jobName + " executing at " + new Date());
} }
/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/ package org.quartz.examples.example8; import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar; import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SchedulerMetaData;
import org.quartz.SimpleTrigger;
import org.quartz.examples.example2.SimpleJob;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.AnnualCalendar;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger; /**
* This example will demonstrate how calendars can be used
* to exclude periods of time when scheduling should not
* take place.
*
*/
public class CalendarExample { public void run() throws Exception {
final Logger log = LoggerFactory.getLogger(CalendarExample.class); log.info("------- Initializing ----------------------"); // First we must get a reference to a scheduler
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler(); log.info("------- Initialization Complete -----------"); log.info("------- Scheduling Jobs -------------------"); // Add the holiday calendar to the schedule
AnnualCalendar holidays = new AnnualCalendar(); // fourth of July (July 4)
Calendar fourthOfJuly = new GregorianCalendar(2005, 6, 4);
holidays.setDayExcluded(fourthOfJuly, true);
// halloween (Oct 31)
Calendar halloween = new GregorianCalendar(2005, 9, 31);
holidays.setDayExcluded(halloween, true);
// christmas (Dec 25)
Calendar christmas = new GregorianCalendar(2005, 11, 25);
holidays.setDayExcluded(christmas, true); // tell the schedule about our holiday calendar
sched.addCalendar("holidays", holidays, false, false); // schedule a job to run hourly, starting on halloween
// at 10 am
Date runDate = TriggerUtils.getDateOf(0,0, 10, 31, 10);
JobDetail job = new JobDetail("job1", "group1", SimpleJob.class);
SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1",
runDate,
null,
SimpleTrigger.REPEAT_INDEFINITELY,
60L * 60L * 1000L);
// tell the trigger to obey the Holidays calendar!
trigger.setCalendarName("holidays"); // schedule the job and print the first run date
Date firstRunTime = sched.scheduleJob(job, trigger); // print out the first execution date.
// Note: Since Halloween (Oct 31) is a holiday, then
// we will not run unti the next day! (Nov 1)
log.info(job.getFullName() +
" will run at: " + firstRunTime +
" and repeat: " + trigger.getRepeatCount() +
" times, every " + trigger.getRepeatInterval() / 1000 + " seconds"); // All of the jobs have been added to the scheduler, but none of the jobs
// will run until the scheduler has been started
log.info("------- Starting Scheduler ----------------");
sched.start(); // wait 30 seconds:
// note: nothing will run
log.info("------- Waiting 30 seconds... --------------");
try {
// wait 30 seconds to show jobs
Thread.sleep(30L * 1000L);
// executing...
} catch (Exception e) {
} // shut down the scheduler
log.info("------- Shutting Down ---------------------");
sched.shutdown(true);
log.info("------- Shutdown Complete -----------------"); SchedulerMetaData metaData = sched.getMetaData();
log.info("Executed " + metaData.getNumberOfJobsExecuted() + " jobs."); } public static void main(String[] args) throws Exception { CalendarExample example = new CalendarExample();
example.run();
} }
Quartz1.8.5例子(八)的更多相关文章
- Quartz1.8.5例子(二)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- scrapy-splash抓取动态数据例子八
一.介绍 本例子用scrapy-splash抓取界面网站给定关键字抓取咨询信息. 给定关键字:个性化:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站信息 ...
- 从零开始学习Node.js例子八 使用SQLite3和MongoDB
setup.js:初始化数据库 var util = require('util'); var async = require('async'); //npm install async var no ...
- Quartz1.8.5例子(十四)
org.quartz.scheduler.instanceName: PriorityExampleScheduler # Set thread count to 1 to force Trigger ...
- Quartz1.8.5例子(十一)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- Quartz1.8.5例子(十)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- Quartz1.8.5例子(九)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- Quartz1.8.5例子(七)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- Quartz1.8.5例子(六)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
随机推荐
- ECMAScript和JavaScript的联系
ECMAScript是一种规范,一种标准.类似于编程语言的接口,定义好一套规范后,各大浏览器厂商遵循规范各自实现之,同时,也做了一些扩展,这些扩展就是规范里面没有的. JavaScript是一种实现, ...
- Android 自定义View修炼-自定义HorizontalScrollView视图实现仿ViewPager效果
开发过程中,需要达到 HorizontalScrollView和ViewPager的效果,于是直接重写了HorizontalScrollView来达到实现ViewPager的效果. 实际效果图如下: ...
- VC++中 wstring和string的互相转换实现
在VC++开发中,经常会用到string和wstring,这就需要二者之间的转换,项目中封装了wstring和string相互转换的2个函数,实现如下: //将wstring转换成string std ...
- Android(java)学习笔记171:Service生命周期
1.Service的生命周期 Android中的Service(服务)与Activity不同,它是不能和用户交互,不能自己启动的,运行在后台的程序,如果我们退出应用的时候,Servic ...
- RedHat7搭建无人值守自动安装Linux操作系统(PXE+Kickstart)
Kickstart服务器 IP: 192.168.136.253 掩码:255.255.255.0 网关:192.168.136.2 DNS:192.168.136.2 安装部署HTTP服 ...
- artTemplate模板引擎的源码拜读
最初接触的模板引擎还是基于node的ejs,当时觉得很神奇原来还可以这么玩,后来随着学习的深入,使用过jade,doT等,当然还有一些比较火的诸如juicer.underscore还没有深入接触,直到 ...
- 《高性能js》读书笔记
第一章:加载和执行 .浏览器的JavaScript的引擎是编译器层的优化: .当浏览器执行JavaScript代码时,不能同时做其他任何事情(单一进程),意味着 .主流浏览器都允许并行下载JS. .减 ...
- [视频转换] C#VideoConvert视频转换帮助类 (转载)
点击下载 VideoConvert.zip 主要功能如下 .获取文件的名字 .获取文件扩展名 .获取文件类型 .视频格式转为Flv .生成Flv视频的缩略图 .转换文件并保存在指定文件夹下 .转换文件 ...
- Android Studio美化之优雅的logcat
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园: 追风917 先来个图,图样吐sexy: 很简单,跟我走吧,两步: 1. 引入Logger库 首先,这个sexy ...
- AsyncTask理解- Day36or37
AsyncTask理解- Day36or37 mobile 5.0 1.手机归属地查询 AtoolsActivity Assets目录特点 该文件是原生文件,不会对里面的文件进行编码 该文件只支持读取 ...