I have a strange problem with java ThreadPool
I define executorService as follows:
ExecutorService executorService = Executors.newFixedThreadPool(5)
and later send tasks:
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 logs some debugging information, including the number of tasks:
log.debug("activeCount={}, completedTaskCount={}, taskCount={}. poolSize={}", new Object[] { activeCount, completedTaskCount,taskCount, poolSize });
after completing some time (after completing task 50-100 in accordance with the pool of filled threads), I see strange behavior - sent tasks are added to the pool queue, but are not executed at all! ThreadPool reported active tasks = 0, a large task queue and count, and none of the tasks were performed in accordance with the log.
Anyone have a problem?
source share