我试着用下面的代码检查Quartz Scheduler状态,但是状态返回令人困惑。为什么在我关闭调度器之后,isStarted状态仍然是真的,在我重新启动调度器之后,isShutDown状态是真的。
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());
}结果是
发布于 2015-09-19 23:28:12
虽然这看起来像是一个bug,但实际上是通过设计来实现的。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;https://stackoverflow.com/questions/30972761
复制相似问题