2016-11-17 35 views
2

後,我有一個石英工作:java的石英停止時間表第一個例外

public class GlobalIdleMonitorJob extends AbstractJob { 

    @Override public void execute(JobExecutionContext context) 
      throws JobExecutionException { 
     try { 
      getJobService().processUserIdle(); 
     }catch(Exception e){ 
      getLogger().error("GlobalIdleMonitorJob",e); 
     } 
    } 
} 

此作業每X秒。我想在第一次失敗後停止這項工作。換句話說,如果

getJobService().processUserIdle(); 

拋出一個異常,我想要這份工作,不僅手動重新啓動或Web應用程序服務器重新啓動後運行了。我應該在catch塊中拋出一個特殊的異常還是如何配置它?

回答

1

您可以將JobExecutionException類對象的setUnscheduleAllTriggers方法設置爲true(true)。請參考官方石英網站下面的例子以供參考。

- documentation

0

在你的catch塊,你可以取消預定這樣的工作:

try { 
    getJobService().processUserIdle(); 
} catch(Exception e) { 
    scheduler.unscheduleJob(triggerKey) 
    getLogger().error("GlobalIdleMonitorJob",e); 
} 

如果你沒有在你的應用程序的任何其他觸發或工作,你可以簡單地調用scheduler.clear() ,但如果你將來可能增加新的工作或觸發器,這不是一個好主意。