18 |
|
import java.util.concurrent.CancellationException; |
19 |
|
import java.util.concurrent.CountDownLatch; |
20 |
|
import java.util.concurrent.ExecutionException; |
21 |
– |
import java.util.concurrent.Executors; |
21 |
|
import java.util.concurrent.ExecutorService; |
22 |
|
import java.util.concurrent.Future; |
23 |
|
import java.util.concurrent.FutureTask; |
90 |
|
final Runnable task = new CheckedRunnable() { |
91 |
|
public void realRun() { done.countDown(); }}; |
92 |
|
p.execute(task); |
93 |
< |
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); |
93 |
> |
await(done); |
94 |
|
} |
95 |
|
} |
96 |
|
|
184 |
|
public void realRun() throws InterruptedException { |
185 |
|
threadStarted.countDown(); |
186 |
|
assertEquals(0, p.getCompletedTaskCount()); |
187 |
< |
threadProceed.await(); |
187 |
> |
await(threadProceed); |
188 |
|
threadDone.countDown(); |
189 |
|
}}); |
190 |
|
await(threadStarted); |
191 |
|
assertEquals(0, p.getCompletedTaskCount()); |
192 |
|
threadProceed.countDown(); |
193 |
< |
threadDone.await(); |
193 |
> |
await(threadDone); |
194 |
|
long startTime = System.nanoTime(); |
195 |
|
while (p.getCompletedTaskCount() != 1) { |
196 |
|
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
274 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
+ |
* The default rejected execution handler is AbortPolicy. |
278 |
+ |
*/ |
279 |
+ |
public void testDefaultRejectedExecutionHandler() { |
280 |
+ |
final ThreadPoolExecutor p = |
281 |
+ |
new ThreadPoolExecutor(1, 2, |
282 |
+ |
LONG_DELAY_MS, MILLISECONDS, |
283 |
+ |
new ArrayBlockingQueue<Runnable>(10)); |
284 |
+ |
try (PoolCleaner cleaner = cleaner(p)) { |
285 |
+ |
assertTrue(p.getRejectedExecutionHandler() |
286 |
+ |
instanceof ThreadPoolExecutor.AbortPolicy); |
287 |
+ |
} |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
/** |
291 |
|
* getRejectedExecutionHandler returns handler in constructor if not set |
292 |
|
*/ |
293 |
|
public void testGetRejectedExecutionHandler() { |
470 |
|
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
471 |
|
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
472 |
|
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
473 |
< |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
474 |
< |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
473 |
> |
assertFalse(p.awaitTermination(randomExpiredTimeout(), |
474 |
> |
randomTimeUnit())); |
475 |
|
long timeoutNanos = 999999L; |
476 |
|
long startTime = System.nanoTime(); |
477 |
|
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
1125 |
|
await(done); |
1126 |
|
}}; |
1127 |
|
for (int i = 0; i < 2; ++i) |
1128 |
< |
p.submit(Executors.callable(task)); |
1128 |
> |
p.execute(task); |
1129 |
|
for (int i = 0; i < 2; ++i) { |
1130 |
|
try { |
1131 |
|
p.execute(task); |
1941 |
|
public void realRun() { |
1942 |
|
done.countDown(); |
1943 |
|
}}); |
1944 |
< |
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); |
1944 |
> |
await(done); |
1945 |
|
} |
1946 |
|
} |
1947 |
|
|
2034 |
|
} |
2035 |
|
} |
2036 |
|
// enough time to run all tasks |
2037 |
< |
assertTrue(done.await(nTasks * SHORT_DELAY_MS, MILLISECONDS)); |
2037 |
> |
await(done, nTasks * SHORT_DELAY_MS); |
2038 |
|
} |
2039 |
|
} |
2040 |
|
|