ScheduledExecutorService会自动销毁吗?
时间: 2023-08-27 20:20:24 浏览: 97
ScheduledExecutorService不会自动销毁。它是一个接口,由程序员负责创建和销毁。在使用ScheduledExecutorService时,需要手动关闭线程池以释放资源。可以调用ScheduledExecutorService的shutdown()方法来关闭线程池,这将阻止新任务的提交并等待已经提交的任务完成执行。另外,可以调用awaitTermination()方法来等待所有任务执行完成后再关闭线程池。需要注意的是,如果没有手动关闭ScheduledExecutorService,它将一直存在,直到程序结束。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [面试阿里问到线程池的问题,“对不起,我学习过这篇线程池讲解,斩神行动开始”](https://blog.csdn.net/GHTFFU/article/details/125788218)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [谨慎使用 ScheduledExecutorService 执行周期性操作](https://blog.csdn.net/joelcat/article/details/107693480)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文