public void wait ( String message , long timeoutInMilliseconds , long intervalInMilliseconds ) { long start = System . currentTimeMillis ( ) ; long end = start + timeoutInMilliseconds ; while ( System . currentTimeMillis ( ) < end ) { if ( until ( ) ) return ; try { Thread . sleep ( intervalInMilliseconds ) ; } catch ( InterruptedException e ) { throw new RuntimeException ( e ) ; } } throw new WaitTimedOutException ( message ) ; }
Wait until the until condition returns true or time runs out .