test/java/util/concurrent/ThreadPoolExecutor/Custom.java
Print this page
*** 41,51 ****
if (x == null ? y == null : x.equals(y)) pass();
else {System.out.println(x + " not equal to " + y); fail(); }}
private static class CustomTask<V> extends FutureTask<V> {
! public final static AtomicInteger births = new AtomicInteger(0);
CustomTask(Callable<V> c) { super(c); births.getAndIncrement(); }
CustomTask(Runnable r, V v) { super(r, v); births.getAndIncrement(); }
}
private static class CustomTPE extends ThreadPoolExecutor {
--- 41,51 ----
if (x == null ? y == null : x.equals(y)) pass();
else {System.out.println(x + " not equal to " + y); fail(); }}
private static class CustomTask<V> extends FutureTask<V> {
! public static final AtomicInteger births = new AtomicInteger(0);
CustomTask(Callable<V> c) { super(c); births.getAndIncrement(); }
CustomTask(Runnable r, V v) { super(r, v); births.getAndIncrement(); }
}
private static class CustomTPE extends ThreadPoolExecutor {
*** 61,71 ****
return new CustomTask<V>(r, v);
}
}
private static class CustomSTPE extends ScheduledThreadPoolExecutor {
! public final static AtomicInteger decorations = new AtomicInteger(0);
CustomSTPE() {
super(threadCount);
}
protected <V> RunnableScheduledFuture<V> decorateTask(
Runnable r, RunnableScheduledFuture<V> task) {
--- 61,71 ----
return new CustomTask<V>(r, v);
}
}
private static class CustomSTPE extends ScheduledThreadPoolExecutor {
! public static final AtomicInteger decorations = new AtomicInteger(0);
CustomSTPE() {
super(threadCount);
}
protected <V> RunnableScheduledFuture<V> decorateTask(
Runnable r, RunnableScheduledFuture<V> task) {
*** 87,97 ****
if (t != null && t.getName().matches("pool-[0-9]+-thread-[0-9]+"))
count++;
return count;
}
! private final static int threadCount = 10;
public static void main(String[] args) throws Throwable {
CustomTPE tpe = new CustomTPE();
equal(tpe.getCorePoolSize(), threadCount);
equal(countExecutorThreads(), 0);
--- 87,97 ----
if (t != null && t.getName().matches("pool-[0-9]+-thread-[0-9]+"))
count++;
return count;
}
! private static final int threadCount = 10;
public static void main(String[] args) throws Throwable {
CustomTPE tpe = new CustomTPE();
equal(tpe.getCorePoolSize(), threadCount);
equal(countExecutorThreads(), 0);