gpt4 book ai didi

java - ThreadPool 不运行提交的任务

转载 作者:搜寻专家 更新时间:2023-11-01 03:29:18 28 4
gpt4 key购买 nike


我对 java ThreadPool 有一个奇怪的问题

我定义 executorService 如下:

ExecutorService executorService = Executors.newFixedThreadPool(5)

然后提交任务:

while (!manager.stop()) {
File file = getFile();
if (file != null) {
String name = file.getName();
log.debug("add new task with name {}", name);
outExecutorInfo();
Future<?> task = executorService.submit(getTask(file));
outTaskInfo(task);
executeTasks.put(name, task);
outExecuteTasks();
}
}

outExecuteTasks 记录一些调试信息,包括任务计数:

log.debug("activeCount={}, completedTaskCount={}, taskCount={}. poolSize={}", 
new Object[] { activeCount, completedTaskCount,taskCount, poolSize });

运行一段时间后(根据线程池 completedTask 计数器执行 50-100 个任务后)我看到奇怪的行为 - 提交的任务附加到池队列但根本没有执行! ThreadPool 报告 Activity 任务 = 0,任务队列大小很大且正在计数,并且没有任务根据日志执行。
有人有问题吗?

最佳答案

好吧,我收集了足够的统计数据说:这是具体的 linux 内核的问题

[root@mag]$ uname -a
Linux ns.mag 2.4.20-8smp #1 SMP Thu Mar 13 17:45:54 EST 2003 i686 i686 i386 GNU/Linux

红帽盒子。即使在 2.4.31 及更高版本上也不会重现。

关于java - ThreadPool 不运行提交的任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4790543/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com