我是靠谱客的博主 留胡子硬币,这篇文章主要介绍ThreadPoolExecutor 如何判断空闲线程,现在分享给大家,希望可以做个参考。

Worker
 public void run() {
            runWorker(this);
 }
        
while (task != null || (task = getTask()) != null) {
 Runnable r = timed ?
                    workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS) :
                    workQueue.take();
                if (r != null)
                    return r;
                    
                    

添加工作线程并启动后,工作线程不段的从队列获取任务,
当超时获取不到任务,超时标志设置为true, 下一次循环判断超时,返回null,
则跳出工作循环,执行 processWorkerExit(w, completedAbruptly);
打断空闲线程 interruptIdleWorkers t.interrupt();

最后

以上就是留胡子硬币最近收集整理的关于ThreadPoolExecutor 如何判断空闲线程的全部内容,更多相关ThreadPoolExecutor内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(114)

评论列表共有 0 条评论

立即
投稿
返回
顶部