[英]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.