66 import java.security.Policy; |
66 import java.security.Policy; |
67 import java.security.ProtectionDomain; |
67 import java.security.ProtectionDomain; |
68 import java.security.SecurityPermission; |
68 import java.security.SecurityPermission; |
69 import java.util.ArrayList; |
69 import java.util.ArrayList; |
70 import java.util.Arrays; |
70 import java.util.Arrays; |
|
71 import java.util.Collections; |
71 import java.util.Date; |
72 import java.util.Date; |
72 import java.util.Enumeration; |
73 import java.util.Enumeration; |
73 import java.util.Iterator; |
74 import java.util.Iterator; |
74 import java.util.List; |
75 import java.util.List; |
75 import java.util.NoSuchElementException; |
76 import java.util.NoSuchElementException; |
87 import java.util.concurrent.RecursiveTask; |
88 import java.util.concurrent.RecursiveTask; |
88 import java.util.concurrent.RejectedExecutionHandler; |
89 import java.util.concurrent.RejectedExecutionHandler; |
89 import java.util.concurrent.Semaphore; |
90 import java.util.concurrent.Semaphore; |
90 import java.util.concurrent.SynchronousQueue; |
91 import java.util.concurrent.SynchronousQueue; |
91 import java.util.concurrent.ThreadFactory; |
92 import java.util.concurrent.ThreadFactory; |
|
93 import java.util.concurrent.ThreadLocalRandom; |
92 import java.util.concurrent.ThreadPoolExecutor; |
94 import java.util.concurrent.ThreadPoolExecutor; |
93 import java.util.concurrent.TimeoutException; |
95 import java.util.concurrent.TimeoutException; |
94 import java.util.concurrent.atomic.AtomicBoolean; |
96 import java.util.concurrent.atomic.AtomicBoolean; |
95 import java.util.concurrent.atomic.AtomicReference; |
97 import java.util.concurrent.atomic.AtomicReference; |
96 import java.util.regex.Matcher; |
98 import java.util.regex.Matcher; |
1276 /** |
1278 /** |
1277 * Spin-waits up to the specified number of milliseconds for the given |
1279 * Spin-waits up to the specified number of milliseconds for the given |
1278 * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
1280 * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
1279 */ |
1281 */ |
1280 void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
1282 void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
1281 long startTime = System.nanoTime(); |
1283 long startTime = 0L; |
1282 for (;;) { |
1284 for (;;) { |
1283 Thread.State s = thread.getState(); |
1285 Thread.State s = thread.getState(); |
1284 if (s == Thread.State.BLOCKED || |
1286 if (s == Thread.State.BLOCKED || |
1285 s == Thread.State.WAITING || |
1287 s == Thread.State.WAITING || |
1286 s == Thread.State.TIMED_WAITING) |
1288 s == Thread.State.TIMED_WAITING) |
1287 return; |
1289 return; |
1288 else if (s == Thread.State.TERMINATED) |
1290 else if (s == Thread.State.TERMINATED) |
1289 fail("Unexpected thread termination"); |
1291 fail("Unexpected thread termination"); |
|
1292 else if (startTime == 0L) |
|
1293 startTime = System.nanoTime(); |
1290 else if (millisElapsedSince(startTime) > timeoutMillis) { |
1294 else if (millisElapsedSince(startTime) > timeoutMillis) { |
1291 threadAssertTrue(thread.isAlive()); |
1295 threadAssertTrue(thread.isAlive()); |
1292 return; |
1296 return; |
1293 } |
1297 } |
1294 Thread.yield(); |
1298 Thread.yield(); |
1898 static final ExecutorService cachedThreadPool = |
1902 static final ExecutorService cachedThreadPool = |
1899 new ThreadPoolExecutor(0, Integer.MAX_VALUE, |
1903 new ThreadPoolExecutor(0, Integer.MAX_VALUE, |
1900 1000L, MILLISECONDS, |
1904 1000L, MILLISECONDS, |
1901 new SynchronousQueue<Runnable>()); |
1905 new SynchronousQueue<Runnable>()); |
1902 |
1906 |
|
1907 static <T> void shuffle(T[] array) { |
|
1908 Collections.shuffle(Arrays.asList(array), ThreadLocalRandom.current()); |
|
1909 } |
1903 } |
1910 } |