JDK-6454289 : ScheduledThreadPoolExecutor spins while waiting for delayed tasks after shutdown
  • 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-07-28
  • 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
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

Comments
EVALUATION Doug Lea is providing a fix.
05-09-2006

EVALUATION When in SHUTDOWN mode, ThreadPoolExecutor calls queue.poll() instead of timed poll, in a tight loop until the workqueue is empty. I think we need to use timed poll unconditionally, but this makes it harder to guarantee pool termination when in SHUTDOWN mode.
28-07-2006