'JAVA-ThreadPoolExecutor why we need to judge the worker count in the execute function during the recheck procedure?

I understand that we need to recheck if the TPE is running when we add a new task, but my question is why we need to judge if the workerCountOf(recheck) is equal to 0? My understanding is that if the TPE is running during the recheck, the task will guaranteed to be executed by the TPE. So I think it is the TPE's responsibility to check if there is any thread left to execute the task, not the submitter!

so am i right ?

the code as below:

public void execute(Runnable command) {
    if (command == null)
        throw new NullPointerException();
    int c = ctl.get();
    if (workerCountOf(c) < corePoolSize) {
        if (addWorker(command, true))
            return;
        c = ctl.get();
    }
    if (isRunning(c) && workQueue.offer(command)) {
        int recheck = ctl.get();
        if (! isRunning(recheck) && remove(command))
            reject(command);
        else if (workerCountOf(recheck) == 0) // ????
            addWorker(null, false);
    }
    else if (!addWorker(command, false))
        reject(command);
}


Solution 1:[1]

But a core thread never quits when it has finished working, even if there are no tasks in the queue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Ziv