/*
* 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. Jmeter聚合报告分析

    Label:每个 JMeter 的 element(例如 HTTP Request)都有一个 Name 属性,这里显示的就是 Name 属性的值 Average:平均响应时间--默认情况下是单个 Re ...

  2. 【转】android蓝牙开发 蓝牙设备的查找和连接

    1.  首先,要操作蓝牙,先要在AndroidManifest.xml里加入权限 // 管理蓝牙设备的权限 <uses-permissionandroid:name="android. ...

  3. MobilePhone正则表达式

    电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号) ((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3} ...

  4. Spark 1.0.0版本号公布

    前言 今天Spark最终跨出了里程碑的一步,1.0.0版本号的公布标志着Spark已经进入1.0时代.1.0.0版本号不仅增加了非常多新特性,而且提供了更好的API支持.Spark SQL作为一个新的 ...

  5. Java用链表实现栈和队列

    1.用链表实现栈 package stack; /** * * @author denghb * */ class Link { public long dData; public Link next ...

  6. Java高级--Java线程运行栈信息的获取 getStackTrace()

    我们在Java程序中使用日志功能(JDK Log或者Log4J)的时候,会发现Log系统会自动帮我们打印出丰富的信息,格式一般如下:为了免去解析StackTrace字符串的麻烦,JDK1.4引入了一个 ...

  7. GitHub与Versions

    [第一步]建立先仓库 第一步的话看一般的提示就知道了,在github新建一个repository(谷歌可以解决),都是可视化的界面操作,所以难度不大.或者看这里:https://help.github ...

  8. MKServerBuilder.psd1

    MKServerBuilder.psd1 # # Module manifest for module 'MKServerBuilder' # # Generated by: Edward Guan ...

  9. JS实例(二)

    一:注册页面 包括非空验证.邮箱验证.密码相等验证,在输入之前提示文字,获得焦点时文字清除颜色变化,输入正确显示正确图片,错误显示错误图片,所有验证通过才可提交,重置会重置回初始模样. 效果图如下: ...

  10. HDU-1037(水水水题)

    Keep on Truckin' Problem Description Boudreaux and Thibodeaux are on the road again . . . "Boud ...