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);
