/*
* 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例子(六)的更多相关文章

  1. Quartz1.8.5例子(二)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  2. ZooKeeper Java例子(六)

    A Simple Watch Client 为了向你介绍ZooKeeper Java API,我们开发了一个非常简单的监视器客户端.ZooKeeper客户端监视一个ZooKeeper节点的改变并且通过 ...

  3. scrapy-splash抓取动态数据例子六

    一.介绍 本例子用scrapy-splash抓取中广互联网站给定关键字抓取咨询信息. 给定关键字:打通:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站信 ...

  4. 计算机网络再次整理————UDP例子[六]

    前言 简单的说,UDP 没有 TCP 用的广泛,但是还有很多是基于UDP的程序的,故而简单介绍一下. 正文 秉承节约脑容量的问题,只做简单的介绍和例子,因为自己几乎也没怎么用过UDP. 只是了解和知晓 ...

  5. 从零开始学习Node.js例子六 EventEmitter发送和接收事件

    pulser.js /* EventEmitter发送和接收事件 HTTPServer和HTTPClient类,它们都继承自EventEmitter EventEmitter被定义在Node的事件(e ...

  6. Quartz1.8.5例子(十四)

    org.quartz.scheduler.instanceName: PriorityExampleScheduler # Set thread count to 1 to force Trigger ...

  7. Quartz1.8.5例子(十一)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  8. Quartz1.8.5例子(十)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  9. Quartz1.8.5例子(九)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

随机推荐

  1. java 大数据处理之内存溢出解决办法(一)

    http://my.oschina.net/songhongxu/blog/209951 一.内存溢出类型 1.java.lang.OutOfMemoryError: PermGen space JV ...

  2. 搭建PHP开发环境 apache+MySQL+PHP 安装phpMyAdmin模块

    该博文参考的资料来源于: http://wenku.baidu.com/view/0e4c569ddd3383c4bb4cd267.html http://www.cnblogs.com/pharen ...

  3. Microsoft SyncToy 文件同步工具

    Microsoft SyncToy SyncToy 是由 微软 推出的一款免费的文件夹同步工具.虽然名字中有一个 Toy,但是大家可千万不要误以为它的功能弱爆了.实际上,我感觉这款软件还真是摆脱了微软 ...

  4. 【转】Android 混淆代码总结

    http://blog.csdn.net/lovexjyong/article/details/24652085 为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的 ...

  5. a href=#与 a href=javascript:void(0) 的差别

    a href="#"> 点击链接后,页面会向上滚到页首,# 默认锚点为 #TOP <a href="javascript:void(0)" onCl ...

  6. HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. SVN工具的使用 和在Eclipse中安装GPD插件:(多步审批流,因此选择使用工作流(JBPM)来实现)

    前言 重点解说SVN工具的还原版本号.   1.提交svn之前.要先更新文件.假设更新之后有版本号冲突的话.就线下解决掉冲突,在把该文件标记为已经解决冲突. 正文 使用SVN还原历史版本号 water ...

  8. python学习笔记--Django入门三 Django 与数据库的交互:数据建模

    把数据存取逻辑.业务逻辑和表现逻辑组合在一起的概念有时被称为软件架构的 Model-View-Controller (MVC)模式.在这个模式中, Model 代表数据存取层,View 代表的是系统中 ...

  9. Java基础知识强化之网络编程笔记04:UDP之发送端的数据来自于键盘录入案例

    1. 数据来自于键盘录入 键盘录入数据要自己控制录入结束. 2. 代码实现: (1)发送端: package com.himi.updDemo1; import java.io.IOException ...

  10. RedHat7搭建PHP开发环境(Zend Studio)

    下载Zend Studio # wget http://downloads.zend.com/studio-eclipse/13.0.1/ZendStudio-13.0.1-linux.gtk.x86 ...