-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b08
-
generic
-
generic
-
Not verified
Neal wrote:
>> Executor seems to take roughly a minute to replace threads that have
>> died, rather than replacing them immediately.
--------------
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
public class Bug5 {
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(); }};
static void report(String label, ThreadPoolExecutor tpe) {
System.out.printf("%10s: active=%d, submitted=%d, completed=%d%n",
label,
Thread.activeCount() - 1,
tpe.getTaskCount(),
tpe.getCompletedTaskCount());
}
public static void main(String[] args) throws Throwable {
Thread.setDefaultUncaughtExceptionHandler(handler);
final int count = 8;
final CyclicBarrier barrier = new CyclicBarrier(count + 1);
ThreadPoolExecutor tpe =
new ThreadPoolExecutor(10, 30, 1L, TimeUnit.HOURS,
new LinkedBlockingQueue<Runnable>());
report("newborn", tpe);
for (int i = 0; i < count; i++)
tpe.execute(new Runnable() {
public void run() {
try { barrier.await(); barrier.await(); }
catch (Throwable t) { t.printStackTrace(); }
}});
barrier.await();
report("started", tpe);
barrier.await();
Thread.sleep(1000);
report("idling", tpe);
for (int i = 0; i < count; i++)
tpe.execute(new Runnable() {
public void run() {
throw new RuntimeException();
}});
Thread.sleep(1000);
report("thrown", tpe);
System.out.printf("Shutting down...%n");
tpe.shutdown();
tpe.awaitTermination(1L, TimeUnit.HOURS);
report("terminated", tpe);
}
}
--------------
$ jver 6 jr Bug5
==> javac -source 1.6 -Xlint:all Bug5.java
==> java -esa -ea Bug5
newborn: active=0, submitted=0, completed=0
started: active=8, submitted=8, completed=0
idling: active=8, submitted=8, completed=8
thrown: active=2, submitted=8, completed=8
Shutting down...
terminated: active=0, submitted=8, completed=8
The active count should not go down to 2.
>> Executor seems to take roughly a minute to replace threads that have
>> died, rather than replacing them immediately.
--------------
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
public class Bug5 {
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(); }};
static void report(String label, ThreadPoolExecutor tpe) {
System.out.printf("%10s: active=%d, submitted=%d, completed=%d%n",
label,
Thread.activeCount() - 1,
tpe.getTaskCount(),
tpe.getCompletedTaskCount());
}
public static void main(String[] args) throws Throwable {
Thread.setDefaultUncaughtExceptionHandler(handler);
final int count = 8;
final CyclicBarrier barrier = new CyclicBarrier(count + 1);
ThreadPoolExecutor tpe =
new ThreadPoolExecutor(10, 30, 1L, TimeUnit.HOURS,
new LinkedBlockingQueue<Runnable>());
report("newborn", tpe);
for (int i = 0; i < count; i++)
tpe.execute(new Runnable() {
public void run() {
try { barrier.await(); barrier.await(); }
catch (Throwable t) { t.printStackTrace(); }
}});
barrier.await();
report("started", tpe);
barrier.await();
Thread.sleep(1000);
report("idling", tpe);
for (int i = 0; i < count; i++)
tpe.execute(new Runnable() {
public void run() {
throw new RuntimeException();
}});
Thread.sleep(1000);
report("thrown", tpe);
System.out.printf("Shutting down...%n");
tpe.shutdown();
tpe.awaitTermination(1L, TimeUnit.HOURS);
report("terminated", tpe);
}
}
--------------
$ jver 6 jr Bug5
==> javac -source 1.6 -Xlint:all Bug5.java
==> java -esa -ea Bug5
newborn: active=0, submitted=0, completed=0
started: active=8, submitted=8, completed=0
idling: active=8, submitted=8, completed=8
thrown: active=2, submitted=8, completed=8
Shutting down...
terminated: active=0, submitted=8, completed=8
The active count should not go down to 2.
- relates to
-
JDK-6576792 ThreadPoolExecutor methods leak interrupts when run in pool threads
- Resolved