Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8129861

High processor load for ScheduledThreadPoolExecutor with 0 core threads

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 9
    • 8u45
    • core-libs
    • b88
    • x86_64
    • linux_ubuntu

        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

              martin Martin Buchholz
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: