繁体   English   中英

如何多次启动和停止排定的执行程序服务

[英]how to start and stop the scheduledexecutorservice multiple times

我正在使用ScheduledExecutorService,在调用scheduleFuture上的cancel方法之后,无法在其上安排Runnable。 cancel()之后调用scheduleAtFixedRate(runnable, INITIAL_DELAY, INTERVAL, TimeUnit.SECONDS) cancel() ,什么也没发生。 在调用cancel()方法之后,有什么方法可以重新启动ScheduledExecutorService吗?

请查看有关Future及其实现FutureTask的注释。

调用cancel()方法的效果是:

  • subsequent calls to isDone() will always return true. Subsequent
    calls to isCancelled() will always return true if this method
    returned true.
  • Once the computation has completed, the computation cannot be restarted or cancelled.

这意味着,如果对isDone()的调用返回true ,则无论您是否对cancel()进行了调用,都无法使用同一服务实例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM