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

ScheduledThreadPoolExecutor spins while waiting for delayed tasks after shutdown

XMLWordPrintable

    • b08
    • generic
    • generic
    • Not verified

      This program:

      ----------------
      import java.util.*;
      import java.util.concurrent.*;

      public class Perf {
          public static void main(String[] args) throws Throwable {
      final int n = 3;
      final ScheduledThreadPoolExecutor pool
      = new ScheduledThreadPoolExecutor(3);
      pool.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);
      ScheduledFuture<?> future = pool.schedule(
      new Runnable() { public void run() {
      System.out.println("Hey!");}},
      1L, TimeUnit.MINUTES);

      pool.shutdown();
      pool.awaitTermination(1L, TimeUnit.HOURS);
          }
      }
      ----------------
      uses up lots of CPU:

       jver mustang jr Perf
      ==> javac -source 1.6 -Xlint:all Perf.java
      ==> java -esa -ea Perf
      Hey!
      jver mustang jr Perf 48.45s user 0.42s system 75% cpu 1:04.44 total

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: