Quartz Scheduler当任务中出现异常时的处理策略(JobExecutionExceptions)
2013-05-27 22:23
363 查看
Quartz当JOB中出现异常时的处理策略
正常情况下,如果当一个任务(job)的方法中出现异常时,Scheduler引擎不会处理这个异常,这个任务还是会按照触发器设定的时间正常触发!
但是Scheduler引擎为我们提供了一个异常(JobExecutionExceptions),当任务出现异常时,我们将异常转换为JobExecutionExceptions异常抛出,从而可以控制调度引擎的操作。
一、立即重新执行该任务
当任务中出现异常时,我们捕获它,然后转换为JobExecutionExceptions异常抛出,同时可以控制调度引擎立即重新执行这个任务(注意红色代码)。
二、取消所有与这个任务关联的触发器
正常情况下,如果当一个任务(job)的方法中出现异常时,Scheduler引擎不会处理这个异常,这个任务还是会按照触发器设定的时间正常触发!
但是Scheduler引擎为我们提供了一个异常(JobExecutionExceptions),当任务出现异常时,我们将异常转换为JobExecutionExceptions异常抛出,从而可以控制调度引擎的操作。
一、立即重新执行该任务
当任务中出现异常时,我们捕获它,然后转换为JobExecutionExceptions异常抛出,同时可以控制调度引擎立即重新执行这个任务(注意红色代码)。
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.refireImmediately(); throw e2; }
二、取消所有与这个任务关联的触发器
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; }
相关文章推荐
- 在word开发中,跨文件数据拷贝粘贴出现ComException(“组织策略阻止了该操作“)异常的处理方式
- hadoop运行job任务出现异常
- Android学习中ADT创建工程后出现appcompat_V7包和自定义包异常处理方法(文章转移)
- SURF角点检测出现错误:SURF.exe 中的 0x756ad36f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x003fcaf0 处的 cv::Exception。
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 通达OA 工作流执行出现的异常现象处理(图文)
- JNI 学习笔记(三)-- JNI访问数组、引用、异常处理、缓存策略
- 未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll
- C#和Qt实现的对于异常处理的一个使用策略
- SQLserver2000 企业版 出现"进程51发生了严重的异常"错误的处理方法
- 未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll
- 关于struts项目中服务器启动出现异常的处理方式
- 第二十章 排查和调试Web程序 之 设计异常处理策略
- javascript异常处理机制Exceptions
- 关于python安装cx_oracle出现异常情况处理
- hadoop 安装出现的几种异常的处理方法,hadoop无法启动,no namenode to stop问题的解决方法,no datanode
- 有效处理C#中异常出现的相关事项
- 处理elasticsearch中的NODENOTAVAILABLEEXCEPTIONS异常
- 2014-10-31Android学习------导入第三包出现的异常处理