2013年4月6日 星期六

Quartz初體驗 - 從Job中自行關閉自己


  1. 於public void execute(JobExecutionContext arg0) throws JobExecutionException自行拋出JobExecutionException
  2. 將欲拋出的JobExecutionException設定為setUnscheduleAllTriggers(true)
  3. throw JobExecutionException

 
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
  //do something...
       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;
        }
}

參考:Example - Dealing with Job Exceptions

沒有留言:

張貼留言