FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
14.0.0 Darwin Kernel Version 14.0.0
A DESCRIPTION OF THE PROBLEM :
When ThreadPoolExecutor.keepAliveTime is 0 and workQueue is a DelayQueue (i.e. the executor is a ScheduledThreadPoolExecutor), the loop in the private getTask method spins without yielding or timed waiting. The problematic piece of code is:
Runnable r = timed ?
workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS) :
workQueue.take();
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This code reproduces the problem:
public static void main(String[] args) throws InterruptedException {
ScheduledExecutorService e = Executors.newScheduledThreadPool(0);
e.schedule(() -> {}, 60, TimeUnit.SECONDS);
Thread.sleep(60000);
}
For 60 seconds, "top" shows 100% CPU on one core.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
While waiting for the next task, the worker thread should use blocking timed wait.
ACTUAL -
No blocking wait, 100% CPU spinning.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.util.concurrent.*;
public class TPTest {
public static void main(String[] args) throws InterruptedException {
ScheduledExecutorService e = Executors.newScheduledThreadPool(0);
e.schedule(() -> {}, 60, TimeUnit.SECONDS);
Thread.sleep(60000);
}
}
---------- END SOURCE ----------