コード例 #1
0
 /** Checks that the threads do not terminate within the given millisecond delay. */
 void assertThreadsStayAlive(long millis, Thread... threads) {
   try {
     // No need to optimize the failing case via Thread.join.
     delay(millis);
     for (Thread thread : threads) assertTrue(thread.isAlive());
   } catch (InterruptedException ie) {
     fail("Unexpected InterruptedException");
   }
 }
コード例 #2
0
 /**
  * Spin-waits up to the specified number of milliseconds for the given thread to enter a wait
  * state: BLOCKED, WAITING, or TIMED_WAITING.
  */
 void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
   long startTime = System.nanoTime();
   for (; ; ) {
     Thread.State s = thread.getState();
     if (s == Thread.State.BLOCKED || s == Thread.State.WAITING || s == Thread.State.TIMED_WAITING)
       return;
     else if (s == Thread.State.TERMINATED) fail("Unexpected thread termination");
     else if (millisElapsedSince(startTime) > timeoutMillis) {
       threadAssertTrue(thread.isAlive());
       return;
     }
     Thread.yield();
   }
 }