如何多次启动和停止scheduledexecutorservice
问题描述:
我正在使用ScheduledExecutorService,并且在我将它称为scheduleFuture上的取消方法后,我无法在其上安排Runnable。在cancel()
之后调用scheduleAtFixedRate(runnable, INITIAL_DELAY, INTERVAL, TimeUnit.SECONDS)
,没有任何反应。在调用cancel()
方法后,有什么办法可以重新启动ScheduledExecutorService
?如何多次启动和停止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()
,你不能使用你的服务的同一个实例。
请建议一些方法,我可以启动服务,停止并重新启动它。 – user1128158 2012-02-22 09:27:26