I glanced at execute
method of ThreadPoolExecutor
class. This seems to be very short and simple:
public void execute(Runnable command) {
if (command == null)
throw new NullPointerException();
if (poolSize >= corePoolSize || !addIfUnderCorePoolSize(command)) {
if (runState == RUNNING && workQueue.offer(command)) {
if (runState != RUNNING || poolSize == 0)
ensureQueuedTaskHandled(command);
}
else if (!addIfUnderMaximumPoolSize(command))
reject(command); // is shutdown or saturated
}
}
But nothing seems to be happening if the the condition poolSize >= corePoolSize
is satisfied!
Because of if the first part of a OR
condition is true, the second won't be executed:
if (true || anyMethodWillNotBeExecuted()) { ... }
According to the rules for thread creation, here also is maximumPoolSize
. And in case if the number of threads is equal (or greater than) the corePoolSize
and less than maxPoolSize
the new thread should be created for task or task should be added to queue.
So why in case when poolSize
greater than or equals to corePoolSize
nothing should happen?..