-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b51
-
generic
-
generic
Doug Lea writes:
Re-submitting a task that is rejected but has also been
previously successfully accepted may cause an instance of that task
not to be run.
Test program:
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
public class RecycledTPETask {
public static void main(String[] args) throws Exception {
final int nTasks = 1000;
final AtomicInteger nRun = new AtomicInteger(0);
final Runnable recycledTask = new Runnable() {
public void run() {
nRun.getAndIncrement();
} };
final ThreadPoolExecutor p =
new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS,
new ArrayBlockingQueue(30));
try {
for (int i = 0; i < nTasks; ++i) {
for (;;) {
try {
p.execute(recycledTask);
break;
}
catch (RejectedExecutionException ignore) {
}
}
}
Thread.sleep(5000); // enough time to run all tasks
if (nRun.get() < nTasks)
throw new Error("Started " + nTasks +
" Ran " + nRun.get());
} catch(Exception ex) {
ex.printStackTrace();
} finally {
p.shutdown();
}
}
}
Re-submitting a task that is rejected but has also been
previously successfully accepted may cause an instance of that task
not to be run.
Test program:
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
public class RecycledTPETask {
public static void main(String[] args) throws Exception {
final int nTasks = 1000;
final AtomicInteger nRun = new AtomicInteger(0);
final Runnable recycledTask = new Runnable() {
public void run() {
nRun.getAndIncrement();
} };
final ThreadPoolExecutor p =
new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS,
new ArrayBlockingQueue(30));
try {
for (int i = 0; i < nTasks; ++i) {
for (;;) {
try {
p.execute(recycledTask);
break;
}
catch (RejectedExecutionException ignore) {
}
}
}
Thread.sleep(5000); // enough time to run all tasks
if (nRun.get() < nTasks)
throw new Error("Started " + nTasks +
" Ran " + nRun.get());
} catch(Exception ex) {
ex.printStackTrace();
} finally {
p.shutdown();
}
}
}
- relates to
-
JDK-8198728 java/util/concurrent/ThreadPoolExecutor/ReSubmittedTask.java fails intermitently
-
- Open
-