JDK-8129861 : High processor load for ScheduledThreadPoolExecutor with 0 core threads
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8u45
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2015-06-23
  • Updated: 2016-12-28
  • 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_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux * 3.19.0-21-generic #21-Ubuntu SMP Sun Jun 14 18:31:11 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
This is both tested on my Ubuntu Machine, my colleagues Windows 7 machine and our Cent OS servers (All 64 bits)

A DESCRIPTION OF THE PROBLEM :
You can create a ScheduledThreadPoolExecutor with 0 core threads (https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html#ScheduledThreadPoolExecutor%28int%29)

However if you do and then try to schedule a new task it will allocate 100% of one CPU core until the task is executed. 

This can cause big problems for systems where you schedule a shutdown task when the system starts (causing 100% CPU load forever)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this program and check the CPU load with htop or similar:


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
CPU load should go down, or exception should be thrown.
ACTUAL -
CPU load holds stedy at 100%

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class TestCode {

	
	static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor( 0 );

	public static void main(String[] args) throws IOException 
	{
		executor.schedule( new Runnable(){

			@Override
			public void run()
			{
				System.out.println( "END" );
			}
			
		}, 30, TimeUnit.SECONDS );
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use 1 core thread instead of 0. However that wastes resources 


Comments
Looks like yet another zero-core thread bug, fixed in the Great jsr166 jdk9 integration
12-10-2015

1. Run the attached test code (TestCode.java) in Windows 7 and Linux OS 2. Checked this with JDK 7u80, 8u45, 8u60 ea b19, and 9 ea b69. Result: ------ 7u80: 54% CPU Load 8: 34 8u45: 42% 8u60 ea b19: 54% 9 ea b69: 40% 3. Conclusion: I'm not able to reproduce this issue as reported by the submitter. The max CPU load recorded is 54%. Moving this up for further review.
25-06-2015