2015-06-22 112 views
0

我嘗試使用下面的代碼檢查Quartz Scheduler狀態,但狀態返回令人困惑。爲什麼在關閉調度程序後,isStarted狀態仍然爲true,在重新啓動調度程序後,isShutDown狀態爲true。Java Quartz Scheduler狀態

if (logger.isLoggable(Level.INFO)) { 
    logger.info("Before: Stand by: " 
     + this.scheduler.isInStandbyMode() + ", Start: " 
     + this.scheduler.isStarted() + ", Shutdown: " 
     + this.scheduler.isShutdown()); 
} 

this.scheduler.start(); 

if (logger.isLoggable(Level.INFO)) { 
    logger.info("After: Stand by: " 
     + this.scheduler.isInStandbyMode() + ", Start: " 
     + this.scheduler.isStarted() + ", Shutdown: " 
     + this.scheduler.isShutdown()); 
} 

//Shutdown scheduler 
this.scheduler.shutdown(true); 
if (logger.isLoggable(Level.INFO)) { 
    logger.info("Schedule stop: Stand by: " 
      + this.scheduler.isInStandbyMode() + ", Start: " 
      + this.scheduler.isStarted() + ", Shutdown: " 
      + this.scheduler.isShutdown()); 
} 

//Restart scheduler 
this.scheduler.start(); 
if (logger.isLoggable(Level.INFO)) { 
    logger.info("schedule start: Stand by: " 
      + this.scheduler.isInStandbyMode() + ", Start: " 
      + this.scheduler.isStarted() + ", Shutdown: " 
      + this.scheduler.isShutdown()); 
} 

而結果回報

  • 信息:前:站在一邊:真,開始:假的,關機:假
  • INFO:後:通過支架:假的,啓動:真實,關機:假
  • 信息:計劃停止:通過支架:真實,開始:真,關機:真
  • 信息:計劃的開始:通過支架:真實,開始:真,關機:真

回答

0

雖然這可能看起來像一個錯誤,但它實際上是通過設計。 isStarted()isShutdown()方法不會報告Quartz Scheduler的當前狀態,而只是用於確定在過去的某個時間點Scheduler是否已啓動或關閉。請參閱以下Javadoc:

/** 
* Whether the scheduler has been started. 
* 
* <p> 
* Note: This only reflects whether <code>{@link #start()}</code> has ever 
* been called on this Scheduler, so it will return <code>true</code> even 
* if the <code>Scheduler</code> is currently in standby mode or has been 
* since shutdown. 
* </p> 
* 
* @see #start() 
* @see #isShutdown() 
* @see #isInStandbyMode() 
*/  
boolean isStarted() throws SchedulerException; 
相關問題