Code Review 7091003: ScheduledExecutorService never executes Runnable with corePoolSize of zero
David Holmes
david.holmes at oracle.com
Thu Sep 22 21:45:42 UTC 2011
Sorry Doug/Chris I should have seen this previously, the order here is
wrong:
1552 void ensurePrestart() {
1553 int wc = workerCountOf(ctl.get());
1554 if (wc == 0)
1555 addWorker(null, false);
1556 else if (wc < corePoolSize)
1557 addWorker(null, true);
1558 }
this will always mark the first worker as non-core even if the
corePoolSize is > 0. It needs to be swapped
void ensurePrestart() {
int wc = workerCountOf(ctl.get());
if (wc < corePoolSize)
addWorker(null, true);
else if (wc == 0) // corePoolSize must be 0
addWorker(null, false);
}
David
-----
On 23/09/2011 2:54 AM, Chris Hegarty wrote:
> This change is coming from Doug Lea's CVS and I've already review it.
>
> It seems that in the re-work that was done for Java 7 we dropped this
> corner case.
>
> STPE.delayedExecute will add the task to the work queue and invoke
> prestartCoreThread. But prestartCoreThread checks for the worker count
> (0) being less than corePoolSize (0) and as that is not the case nothing
> happens. So we have a task in the queue but no thread waiting to execute
> it.
>
> For STPE when the queue is not empty there must always be at least one
> thread waiting on the queue.
>
> http://cr.openjdk.java.net/~chegar/7091003/webrev.00/webrev/
>
> -Chris.
More information about the core-libs-dev
mailing list