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

Decreasing ScheduledThreadPoolExecutor core pool size causes busy spin

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 6
    • core-libs
    • b93
    • 6
    • b09
    • x86
    • windows_2003
    • Not verified

      FULL PRODUCT VERSION :
      1.6.0
      build 1.6.0-b105

      ADDITIONAL OS VERSION INFORMATION :
      ALL Windows (XP, 2003)

      A DESCRIPTION OF THE PROBLEM :
      Very high CPU load when decreasing the CorePoolSize of ThreadPoolExecutor.
      Decreasing it at runtime through setCorePoolSize() .

      It results from a change in the implementation of ThreadPoolExecutor.getTask() .

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this simple code using JDK6:

      package com.clearforest.bugs.jdk6;

      import java.util.concurrent.*;
      import java.util.concurrent.atomic.AtomicInteger;

      public class CPUBugDemo
      {
      static private AtomicInteger sm_counter = new AtomicInteger(0);
      static private ScheduledFuture[] sm_workers = null;
      static private ScheduledThreadPoolExecutor sm_thrdPool = new ScheduledThreadPoolExecutor(10);

      /**
      * @param args
      */
      public static void main(String[] args)
      {

      Runnable rnbl = new Runnable()
      {
      public void run()
      {
      Execute1();
      }
      };

      sm_workers = new ScheduledFuture[10];
      long lDelay = 100L;
      for(int i = 0 ; i < sm_workers.length ; i++)
      {
      sm_workers[i] = sm_thrdPool.scheduleAtFixedRate(rnbl, lDelay, 1000L, TimeUnit.MILLISECONDS);
      lDelay += (100L);
      }

      {
      try
      {
      Thread.sleep(3000);
      System.out.println("************************************************************");
      // The next line will cause very high CPU load!
      sm_thrdPool.setCorePoolSize(sm_thrdPool.getCorePoolSize() - 3);
      }
      catch(Exception ex)
      {

      }
      }

      }

      static private void Execute1()
      {
      int tmpInt = sm_counter.getAndIncrement();
      if( ( tmpInt % 10) == 0)
      System.out.println(Long.toString(Thread.currentThread().getId()) + " ==> " + Integer.toString(tmpInt));
      }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No CPU load
      ACTUAL -
      Very high CPU load

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package com.clearforest.bugs.jdk6;

      import java.util.concurrent.*;
      import java.util.concurrent.atomic.AtomicInteger;

      public class CPUBugDemo
      {
      static private AtomicInteger sm_counter = new AtomicInteger(0);
      static private ScheduledFuture[] sm_workers = null;
      static private ScheduledThreadPoolExecutor sm_thrdPool = new ScheduledThreadPoolExecutor(10);

      /**
      * @param args
      */
      public static void main(String[] args)
      {

      Runnable rnbl = new Runnable()
      {
      public void run()
      {
      Execute1();
      }
      };

      sm_workers = new ScheduledFuture[10];
      long lDelay = 100L;
      for(int i = 0 ; i < sm_workers.length ; i++)
      {
      sm_workers[i] = sm_thrdPool.scheduleAtFixedRate(rnbl, lDelay, 1000L, TimeUnit.MILLISECONDS);
      lDelay += (100L);
      }

      {
      try
      {
      Thread.sleep(3000);
      System.out.println("************************************************************");
      // The next line will cause very high CPU load!
      sm_thrdPool.setCorePoolSize(sm_thrdPool.getCorePoolSize() - 3);
      }
      catch(Exception ex)
      {

      }
      }

      }

      static private void Execute1()
      {
      int tmpInt = sm_counter.getAndIncrement();
      if( ( tmpInt % 10) == 0)
      System.out.println(Long.toString(Thread.currentThread().getId()) + " ==> " + Integer.toString(tmpInt));
      }
      }

      ---------- END SOURCE ----------
      -

            martin Martin Buchholz
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: