2015-06-22 297 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; 
相关问题