知识点:Quartz任务异常处理方式

Quartz提供了二种解决方法

1 立即重新执行任务


2 立即停止所有相关这个任务的触发器

解决的方式是:在你的程序出错时,用Quartz提供的JobExecutionException类相关方法就能很好的解决

1.立即重新执行任务

try {  
           int zero = 0;  
           @SuppressWarnings("unused")  
           int calculation = 4815 / zero;  
       } catch (Exception e) {  
           _log.error("执行任务出错了...");  
           JobExecutionException e2 = new JobExecutionException(e);  
           // 这个工作将立即重新开始  
           e2.setRefireImmediately(true);  
           throw e2;  
       } 

运用的方法为:e2.setRefireImmediately(true);

2.立即停止所有相关这个任务的触发器

try {  
            int zero = 0;  
            @SuppressWarnings("unused")  
            int calculation = 4815 / zero;  
        } catch (Exception e) {  
            _log.info("--- Error in job!");  
            JobExecutionException e2 =   
                new JobExecutionException(e);  
            // 自动取消与此作业关联的所有触发器计划
            e2.setUnscheduleAllTriggers(true);  
            throw e2;  
        }  

运用的方法为:e2.setUnscheduleAllTriggers(true);

猜你喜欢

转载自www.cnblogs.com/nhdlb/p/12095776.html