JDK-8065320 : Busy loop in ThreadPoolExecutor.getTask for ScheduledThreadPoolExecutor
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 8u20,8u25,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-11-15
  • Updated: 2015-11-09
  • Resolved: 2015-10-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b88Resolved
Related Reports
Duplicate :  
Description
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 ----------


Comments
To be fixed in the Great jsr166 jdk9 integration.
12-10-2015

Verified that this is still an issue with 9-b45.
16-01-2015

Tested with JDK 8u25 on MAC and could reproduce this. Could be a duplicate of JDK-8047288.
20-11-2014