-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b08
-
generic
-
generic
-
Not verified
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
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
- relates to
-
JDK-6576792 ThreadPoolExecutor methods leak interrupts when run in pool threads
- Resolved