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

ThreadPoolExecutor very slow to shut down for large poolSize

XMLWordPrintable

    • b08
    • generic
    • generic
    • Not verified

      Shutting down a thread pool with 1000 idle threads takes on the order of 10 seconds.
      The time for shutdown to complete for sufficiently large pool sizes
      is quadratic in the pool size.

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

      public class InterruptStorm {
          public static void main(String[] args) throws Throwable {
      final int n = Integer.parseInt(args[0]);
      final ThreadPoolExecutor pool
      = new ThreadPoolExecutor(n, n, 0L, TimeUnit.SECONDS,
      new LinkedBlockingQueue<Runnable>());
      pool.prestartAllCoreThreads();

      long t0 = System.nanoTime();
      pool.shutdown();
      pool.awaitTermination(1L, TimeUnit.HOURS);
      System.out.printf("%3f%n", ((double) (System.nanoTime() - t0)/
      (1000.0 * 1000.0 * 1000.0)));
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: