【问题标题】:What happens to terminated tasks in a ScheduledExecutorService?ScheduledExecutorService 中终止的任务会发生什么?
【发布时间】:2013-05-26 07:40:23
【问题描述】:

我目前正在修改应用程序以使用 ScheduledExecutorService 代替 Timer,但我不知道如何处理我的旧 Timer.purge()

Executor 是如何处理事情的?我有什么需要担心的吗?

【问题讨论】:

    标签: java multithreading purge scheduledexecutorservice


    【解决方案1】:

    Executor 没有等价物。当任务被取消时,它们的引用将从 Executor 中删除。

    但是 Executor 的生命周期是由 shutdown() 管理的,所以当不再需要 Executor 时应该调用它。

    【讨论】:

    • 我想确保这一点,因为它没有在任何地方提及。我已经将Timer.cancel() 更改为Executor.shutdown()
    猜你喜欢
    • 2022-01-23
    • 1970-01-01
    • 2015-11-25
    • 2016-02-14
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多