JDK-6458339 : ThreadPoolExecutor very slow to shut down for large poolSize
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-08-09
  • Updated: 2011-05-18
  • Resolved: 2011-05-18
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 7
7 b08Fixed
Related Reports
Relates :  
Description
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)));
    }
}

Comments
EVALUATION Submitter is correct. Instead of an exiting worker sending all other idle workers an interrupt, it suffices to send one other worker an interrupt, avoiding the interrupt storm. Fix being provided by Doug Lea.
09-08-2006