JDK-6450207 : ThreadPoolExecutor doesn't count throwing tasks as "completed"
  • 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-19
  • 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
If a task throws, completedTasks is not incremented, which means
both getCompletedTaskCount and getTaskCount are messed up.

The documentation of afterExecute strongly implies that tasks that
throw have "completed", since it distingishes those that have
"completed normally".

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

public class Bug3 {
    private static final AtomicInteger count
	= new AtomicInteger(0);

    private static final Thread.UncaughtExceptionHandler handler
	= new Thread.UncaughtExceptionHandler() {
		public void uncaughtException(Thread t, Throwable e) {
		    count.getAndIncrement(); }};

    public static void main(String[] args) throws Throwable {
	Thread.setDefaultUncaughtExceptionHandler(handler);
	ThreadPoolExecutor tpe =
	    new ThreadPoolExecutor(3, 3, 0L, TimeUnit.SECONDS,
				   new LinkedBlockingQueue<Runnable>());

	for (int i = 0; i < 100; i++)
	    tpe.execute(new Runnable() {
		    public void run() { throw new Error(); }});

	tpe.shutdown();
	tpe.awaitTermination(100L, TimeUnit.HOURS);
	System.out.printf("count=%d%n", count.get());
	System.out.printf("submitted=%d%n", tpe.getTaskCount());
	System.out.printf("completed=%d%n", tpe.getCompletedTaskCount());
    }
}
----


==>

count=100
submitted=0
completed=0

Comments
EVALUATION Submitter is correct.
19-07-2006