public Future submitCall(Callable callable) {
logger.info("Submitting , total task {}, active count {} completed count {} queue size {}, threads in pool currently {}, largest thread pool {} ",
threadPool.getTaskCount(), threadPool.getActiveCount(), threadPool.getCompletedTaskCount(),
threadPool.getQueue().size(), threadPool.getPoolSize(), threadPool.getLargestPoolSize() );
return threadPool.submit(callable);
}
2024-11-27 13:46:33,963 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 200, active count 49 completed count 151 queue size 0, threads in pool currently 200, largest thread pool 200
2024-11-27 13:46:33,963 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 201, active count 49 completed count 151 queue size 1, threads in pool currently 200, largest thread pool 200
2024-11-27 13:46:33,964 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 202, active count 49 completed count 152 queue size 1, threads in pool currently 200, largest thread pool 200
2024-11-27 13:46:33,965 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 203, active count 49 completed count 152 queue size 2, threads in pool currently 200, largest thread pool 200
2024-11-27 13:46:33,966 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 204, active count 50 completed count 152 queue size 2, threads in pool currently 200, largest thread pool 200
2024-11-27 13:46:33,967 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 205, active count 50 completed count 152 queue size 3, threads in pool currently 200, largest thread pool 200
Как мы знаем, для каждой задачи создается новый поток до тех пор, пока не будет достигнут размер основного пула. Однако, как только размер основного пула достигнут, журналы показывают, что количество выполненных задач равно 151, а количество активных задач — 49. Простые потоки можно рассчитать как размер пула — активные потоки, что в данном случае составляет 200–49. . Учитывая, что существуют свободные потоки, почему они не используются повторно для обработки новых задач, а не ставят их в очередь?
Создание ThreadPool [code]@PostConstruct public void postConstruct() { threadPool = new ThreadPoolExecutor(corePoolSize != 0 ? corePoolSize : defaultPoolSize, maxPoolSize != 0 ? maxPoolSize : defaultMaxPoolSize, defaultKeepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue(300000)); } [/code] значения, переданные из файла свойств [code]#ThreadPool corePool.Size=200 maxPool.Size=400 queue.Capacity=999999 KeepAlive=10 [/code] Я отправляю задачу указанным ниже способом [code] public Future submitCall(Callable callable) { logger.info("Submitting , total task {}, active count {} completed count {} queue size {}, threads in pool currently {}, largest thread pool {} ", threadPool.getTaskCount(), threadPool.getActiveCount(), threadPool.getCompletedTaskCount(), threadPool.getQueue().size(), threadPool.getPoolSize(), threadPool.getLargestPoolSize() ); return threadPool.submit(callable); } [/code] журналы [code]2024-11-27 13:46:33,963 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 200, active count 49 completed count 151 queue size 0, threads in pool currently 200, largest thread pool 200 2024-11-27 13:46:33,963 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 201, active count 49 completed count 151 queue size 1, threads in pool currently 200, largest thread pool 200 2024-11-27 13:46:33,964 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 202, active count 49 completed count 152 queue size 1, threads in pool currently 200, largest thread pool 200 2024-11-27 13:46:33,965 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 203, active count 49 completed count 152 queue size 2, threads in pool currently 200, largest thread pool 200 2024-11-27 13:46:33,966 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 204, active count 50 completed count 152 queue size 2, threads in pool currently 200, largest thread pool 200 2024-11-27 13:46:33,967 [INFO ]---[DAExecutorService.java]---[http-nio-9201-exec-2]: Submitting , total task 205, active count 50 completed count 152 queue size 3, threads in pool currently 200, largest thread pool 200 [/code] Как мы знаем, для каждой задачи создается новый поток до тех пор, пока не будет достигнут размер основного пула. Однако, как только размер основного пула достигнут, журналы показывают, что количество выполненных задач равно 151, а количество активных задач — 49. Простые потоки можно рассчитать как размер пула — активные потоки, что в данном случае составляет 200–49. . Учитывая, что существуют свободные потоки, почему они не используются повторно для обработки новых задач, а не ставят их в очередь?