How to remove a task from ScheduledExecutorService?

后端 未结 2 829
难免孤独
难免孤独 2020-12-07 22:22

I have a ScheduledExecutorService that times a few different task periodically with scheduleAtFixedRate(Runnable, INIT_DELAY, ACTION_DELAY, TimeUnit.SECON

2条回答
  •  执念已碎
    2020-12-07 23:08

    If your ScheduledExecutorService instance extends ThreadPoolExecutor (e.g. ScheduledThreadPoolExecutor), you could use remove(Runnable) (but see the note in its javadoc: "It may fail to remove tasks that have been converted into other forms before being placed on the internal queue.") or purge().

提交回复
热议问题