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.example6; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.StatefulJob;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; /**
* <p>
* A job dumb job that will throw a job execution exception
* </p>
*
* @author Bill Kratzer
*/
public class BadJob1 implements StatefulJob { // Logging
private static Logger _log = LoggerFactory.getLogger(BadJob1.class); /**
* Empty public constructor for job initilization
*/
public BadJob1() {
} /**
* <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 {
String jobName = context.getJobDetail().getFullName();
_log.info("---" + jobName + " executing at " + new Date()); // a contrived example of an exception that
// will be generated by this job due to a
// divide by zero error
try {
int zero = 0;
int calculation = 4815 / zero;
} catch (Exception e) {
_log.info("--- Error in job!");
JobExecutionException e2 = new JobExecutionException(e);
// this job will refire immediately
e2.setRefireImmediately(true);
throw e2;
} _log.info("---" + jobName + " completed 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.example6; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.StatefulJob;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; /**
* <p>
* A job dumb job that will throw a job execution exception
* </p>
*
* @author Bill Kratzer
*/
public class BadJob2 implements StatefulJob { // Logging
private static Logger _log = LoggerFactory.getLogger(BadJob2.class); /**
* Empty public constructor for job initilization
*/
public BadJob2() {
} /**
* <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 {
String jobName = context.getJobDetail().getFullName();
_log.info("---" + jobName + " executing at " + new Date()); // a contrived example of an exception that
// will be generated by this job due to a
// divide by zero error
try {
int zero = 0;
int calculation = 4815 / zero;
} catch (Exception e) {
_log.info("--- Error in job!");
JobExecutionException e2 = new JobExecutionException(e);
// Quartz will automatically unschedule
// all triggers associated with this job
// so that it does not run again
e2.setUnscheduleAllTriggers(true);
throw e2;
} _log.info("---" + jobName + " completed 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.example6; import java.util.Date; import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SchedulerMetaData;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.Logger; /**
*
* This job demonstrates how Quartz can handle JobExecutionExceptions that are
* thrown by jobs.
*
* @author Bill Kratzer
*/
public class JobExceptionExample { public void run() throws Exception {
Logger log = LoggerFactory.getLogger(JobExceptionExample.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 -------------------"); // jobs can be scheduled before start() has been called // get a "nice round" time a few seconds in the future...
long ts = TriggerUtils.getNextGivenSecondDate(null, 15).getTime(); // badJob1 will run every three seconds
// this job will throw an exception and refire
// immediately
JobDetail job = new JobDetail("badJob1", "group1", BadJob1.class);
SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1",
new Date(ts), null, SimpleTrigger.REPEAT_INDEFINITELY, 3000L);
Date ft = sched.scheduleJob(job, trigger);
log.info(job.getFullName() + " will run at: " + ft + " and repeat: "
+ trigger.getRepeatCount() + " times, every "
+ trigger.getRepeatInterval() / 1000 + " seconds"); // badJob2 will run every three seconds
// this job will throw an exception and never
// refire
job = new JobDetail("badJob2", "group1", BadJob2.class);
trigger = new SimpleTrigger("trigger2", "group1", new Date(ts), null,
SimpleTrigger.REPEAT_INDEFINITELY, 3000L);
ft = sched.scheduleJob(job, trigger);
log.info(job.getFullName() + " will run at: " + ft + " and repeat: "
+ trigger.getRepeatCount() + " times, every "
+ trigger.getRepeatInterval() / 1000 + " seconds"); log.info("------- Starting Scheduler ----------------"); // jobs don't start firing until start() has been called...
sched.start(); log.info("------- Started Scheduler -----------------"); try {
// sleep for 60 seconds
Thread.sleep(60L * 1000L);
} catch (Exception e) {
} 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 { JobExceptionExample example = new JobExceptionExample();
example.run();
} }
[INFO] 02 二月 03:27:57.488 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Initializing ---------------------- [INFO] 02 二月 03:27:57.511 下午 main [org.quartz.simpl.SimpleThreadPool]
Job execution threads will use class loader of thread: main [INFO] 02 二月 03:27:57.523 下午 main [org.quartz.core.SchedulerSignalerImpl]
Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl [INFO] 02 二月 03:27:57.525 下午 main [org.quartz.core.QuartzScheduler]
Quartz Scheduler v.1.8.5 created. [INFO] 02 二月 03:27:57.526 下午 main [org.quartz.simpl.RAMJobStore]
RAMJobStore initialized. [INFO] 02 二月 03:27:57.526 下午 main [org.quartz.core.QuartzScheduler]
Scheduler meta-data: Quartz Scheduler (v1.8.5) 'DefaultQuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. [INFO] 02 二月 03:27:57.527 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' [INFO] 02 二月 03:27:57.527 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler version: 1.8.5 [INFO] 02 二月 03:27:57.527 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Initialization Complete ------------ [INFO] 02 二月 03:27:57.527 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Scheduling Jobs ------------------- [INFO] 02 二月 03:27:57.532 下午 main [org.quartz.examples.example6.JobExceptionExample]
group1.badJob1 will run at: Tue Feb 02 15:28:00 CST 2016 and repeat: -1 times, every 3 seconds [INFO] 02 二月 03:27:57.532 下午 main [org.quartz.examples.example6.JobExceptionExample]
group1.badJob2 will run at: Tue Feb 02 15:28:00 CST 2016 and repeat: -1 times, every 3 seconds [INFO] 02 二月 03:27:57.532 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Starting Scheduler ---------------- [INFO] 02 二月 03:27:57.533 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. [INFO] 02 二月 03:27:57.533 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Started Scheduler ----------------- [DEBUG] 02 二月 03:27:58.531 下午 Timer-0 [org.quartz.utils.UpdateChecker]
Checking for available updated version of Quartz... [DEBUG] 02 二月 03:28:00.008 下午 DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.simpl.SimpleJobFactory]
Producing instance of Job 'group1.badJob1', class=org.quartz.examples.example6.BadJob2 [DEBUG] 02 二月 03:28:00.030 下午 DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.simpl.SimpleJobFactory]
Producing instance of Job 'group1.badJob2', class=org.quartz.examples.example6.BadJob2 [DEBUG] 02 二月 03:28:00.030 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.core.JobRunShell]
Calling execute on job group1.badJob1 [DEBUG] 02 二月 03:28:00.030 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.core.JobRunShell]
Calling execute on job group1.badJob2 [INFO] 02 二月 03:28:00.031 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.examples.example6.BadJob2]
---group1.badJob1 executing at Tue Feb 02 15:28:00 CST 2016 [INFO] 02 二月 03:28:00.031 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.examples.example6.BadJob2]
---group1.badJob2 executing at Tue Feb 02 15:28:00 CST 2016 [INFO] 02 二月 03:28:00.031 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.examples.example6.BadJob2]
--- Error in job! [INFO] 02 二月 03:28:00.031 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.examples.example6.BadJob2]
--- Error in job! [INFO] 02 二月 03:28:00.033 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.core.JobRunShell]
Job group1.badJob1 threw a JobExecutionException: org.quartz.JobExecutionException: java.lang.ArithmeticException: / by zero [See nested exception: java.lang.ArithmeticException: / by zero]
at org.quartz.examples.example6.BadJob2.execute(BadJob2.java:69)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.ArithmeticException: / by zero
at org.quartz.examples.example6.BadJob2.execute(BadJob2.java:65)
... 2 more
[INFO] 02 二月 03:28:00.033 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.core.JobRunShell]
Job group1.badJob2 threw a JobExecutionException: org.quartz.JobExecutionException: java.lang.ArithmeticException: / by zero [See nested exception: java.lang.ArithmeticException: / by zero]
at org.quartz.examples.example6.BadJob2.execute(BadJob2.java:69)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.ArithmeticException: / by zero
at org.quartz.examples.example6.BadJob2.execute(BadJob2.java:65)
... 2 more
[INFO] 02 二月 03:28:57.545 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Shutting Down --------------------- [INFO] 02 二月 03:28:57.546 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down. [INFO] 02 二月 03:28:57.546 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused. [DEBUG] 02 二月 03:28:57.547 下午 main [org.quartz.simpl.SimpleThreadPool]
shutdown complete [INFO] 02 二月 03:28:57.547 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete. [INFO] 02 二月 03:28:57.562 下午 main [org.quartz.examples.example6.JobExceptionExample]
------- Shutdown Complete ----------------- [INFO] 02 二月 03:28:57.562 下午 main [org.quartz.examples.example6.JobExceptionExample]
Executed 2 jobs. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-3 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-5 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-10 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-6 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-8 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-9 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-7 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:28:57.941 下午 DefaultQuartzScheduler_Worker-4 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down.
两个都改成BadJob2的结果,如果按照原来的额程序,BadJob1将会不停的执行,并且不停的报错!!!!这是不行的
Quartz1.8.5例子(六)的更多相关文章
- Quartz1.8.5例子(二)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- ZooKeeper Java例子(六)
A Simple Watch Client 为了向你介绍ZooKeeper Java API,我们开发了一个非常简单的监视器客户端.ZooKeeper客户端监视一个ZooKeeper节点的改变并且通过 ...
- scrapy-splash抓取动态数据例子六
一.介绍 本例子用scrapy-splash抓取中广互联网站给定关键字抓取咨询信息. 给定关键字:打通:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站信 ...
- 计算机网络再次整理————UDP例子[六]
前言 简单的说,UDP 没有 TCP 用的广泛,但是还有很多是基于UDP的程序的,故而简单介绍一下. 正文 秉承节约脑容量的问题,只做简单的介绍和例子,因为自己几乎也没怎么用过UDP. 只是了解和知晓 ...
- 从零开始学习Node.js例子六 EventEmitter发送和接收事件
pulser.js /* EventEmitter发送和接收事件 HTTPServer和HTTPClient类,它们都继承自EventEmitter EventEmitter被定义在Node的事件(e ...
- 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 ...
随机推荐
- 磁盘性能指标--IOPS 理论
机械硬盘的连续读写性很好, 但随机读写性能很差.这是因为磁头移动至正确的磁道上需要时间,随机读写时,磁头不停的移动,时间都花在了磁头寻道上,所以性能不高. 如下图:在存储小文件(图片).OLTP数据 ...
- pugixml
http://www.firedragonpzy.com.cn/index.php/archives/3227 有关cocos2d-x的xml文件读取问题
- 关于tomcat的思考
下载文件两种方式:绿色版的.安装版的(找到jre的环境变量.配置或修改端口8080→8070) 启动完tomcat之后: 既可以虚拟目录打开(如http://localhost:8070/mldn/) ...
- 如何在Byte[]和String之间进行转换
源自C#与.NET程序员面试宝典. 如何在Byte[]和String之间进行转换? 比特(b):比特只有0 1,1代表有脉冲,0代表无脉冲.它是计算机物理内存保存的最基本单元. 字节(B):8个比特, ...
- Android 自定义View修炼-自定义HorizontalScrollView视图实现仿ViewPager效果
开发过程中,需要达到 HorizontalScrollView和ViewPager的效果,于是直接重写了HorizontalScrollView来达到实现ViewPager的效果. 实际效果图如下: ...
- Linux下搭建Oracle11g RAC(5)----配置ASM磁盘
将共享磁盘格式化.然后用asmlib将其配置为ASM磁盘,用于将来存放OCR.Voting Disk和数据库用. 注意:只需在其中1个节点上格式化就可以,接下来我们选择在node1节点上格式化. 这里 ...
- mysql left用法
LEFT(str,len) 返回字符串str的最左面len个字符. SELECT LEFT('123456789',5)
- Spring 注解回顾
[copy] 参考资料 赵蒙
- css中判断IE版本的语句
css中判断IE版本的语句<!--[if gte IE 6]> Only IE 6/+ <![endif]-->: 1. <!--[if !IE]> 除IE外都可识 ...
- 自动显示git分支--安装oh-my-zsh(Ubuntu环境)
1,安装zsh sudo apt-get install zsh 2,克隆项目 git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh- ...