shuts down an ExecutorService
2024-09-02 23:26:26
- shuts down an ExecutorService in two phases, first by calling shutdown to reject incoming tasks, and then calling shutdownNow, if necessary, to cancel any lingering tasks:
void shutdownAndAwaitTermination(ExecutorService pool) {
pool.shutdown(); // Disable new tasks from being submitted
try {
// Wait a while for existing tasks to terminate
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
pool.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(60, TimeUnit.SECONDS))
System.err.println("Pool did not terminate");
}
} catch (InterruptedException ie) {
// (Re-)Cancel if current thread also interrupted
pool.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
最新文章
- js的并行加载以及顺序执行
- filterHTML
- hibernate查询返回一个list ,Date类型追加数据
- 【leetcode】Integer to Roman
- JAVA的覆盖、继承和多态的详细解说.this和super的用法
- 如何让CRectTracker的m_rect不超出一定的范围,比如screen或者某个document的范围
- 基于anyrtc的sdk实现直播连麦互动
- 原始启动log&;新log
- Java中@Deprecated、@SupressWarning、@Override的作用
- wifi基本原理
- python连接Linux命令行
- 置信区间-显著性-P-值
- gcc ld 链接器相关知识,调试指令(程序员的自我修养----链接、装载与库)
- ubuntu 18.04//18.10&;&;windows 7/10双系统系统时间不一致
- LeetCode(72):编辑距离
- 【转】Python中的字符串与字符编码
- [No0000118]SQL Server附加数据库拒绝访问解决方法汇总
- pyautogui控制鼠标键盘自动填写数据
- VS2017 加载项目 :未找到框架“.NETFramework,Version=v4.7”的引用程序集(出坑指南)
- Centos6.6系统root用户密码恢复案例(转)