25 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
26 |
|
import java.util.concurrent.locks.ReentrantLock; |
27 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
28 |
+ |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
29 |
|
import java.security.AccessControlException; |
30 |
|
import java.security.Policy; |
31 |
|
import java.security.PrivilegedAction; |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
+ |
* awaitTermination on a non-shutdown pool times out |
231 |
+ |
*/ |
232 |
+ |
public void testAwaitTermination_timesOut() throws InterruptedException { |
233 |
+ |
ForkJoinPool p = new ForkJoinPool(1); |
234 |
+ |
assertFalse(p.isTerminated()); |
235 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS)); |
236 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
237 |
+ |
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
238 |
+ |
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
239 |
+ |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
240 |
+ |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
241 |
+ |
long timeoutNanos = 999999L; |
242 |
+ |
long startTime = System.nanoTime(); |
243 |
+ |
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
244 |
+ |
assertTrue(System.nanoTime() - startTime >= timeoutNanos); |
245 |
+ |
assertFalse(p.isTerminated()); |
246 |
+ |
startTime = System.nanoTime(); |
247 |
+ |
long timeoutMillis = timeoutMillis(); |
248 |
+ |
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS)); |
249 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
250 |
+ |
assertFalse(p.isTerminated()); |
251 |
+ |
p.shutdown(); |
252 |
+ |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
253 |
+ |
assertTrue(p.isTerminated()); |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
/** |
257 |
|
* setUncaughtExceptionHandler changes handler for uncaught exceptions. |
258 |
|
* |
259 |
|
* Additionally tests: Overriding ForkJoinWorkerThread.onStart |