zoukankan      html  css  js  c++  java
  • Quartz Scheduler当任务中出现异常时的处理策略(JobExecutionExceptions)

    Quartz当JOB中出现异常时的处理策略

    正常情况下,如果当一个任务(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;
            }

      

     

  • 相关阅读:
    如何用meavn构建mahout项目
    项目分析:对于7种图书推荐算法的组合评测
    项目实战:Mahout构建图书推荐系统
    Mahout推荐算法API详解
    9. Palindrome Number
    26. Remove Duplicates from Sorted Array
    575. Distribute Candies
    单链表的逆置
    回文串的判断
    回文判断(一个栈是不是回文)
  • 原文地址:https://www.cnblogs.com/daxin/p/3102705.html
Copyright © 2011-2022 走看看