protected void waitForThreadToEnterWaitState(Thread thread,long timeoutMillis){
  long startTime=0L;
  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 (startTime == 0L)     startTime=System.nanoTime();
 else     if (millisElapsedSince(startTime) > timeoutMillis) {
      threadAssertTrue(thread.isAlive());
      return;
    }
    Thread.yield();
  }
}

protected void waitForThreadToEnterWaitState ( Thread thread , long timeoutMillis ) { long startTime = 0L ; 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 ( startTime == 0L ) startTime = System . nanoTime ( ) ; else if ( millisElapsedSince ( startTime ) > timeoutMillis ) { threadAssertTrue ( thread . isAlive ( ) ) ; return ; } Thread . yield ( ) ; } }
spin - waits up to the specified number of milliseconds for the given thread to enter a wait state : blocked , waiting , or timed_waiting .
