public synchronized boolean advanceTo ( long endTime ) { if ( endTime < currentTime || runnables . isEmpty ( ) ) { currentTime = endTime ; return false ; } int runCount = 0 ; while ( nextTaskIsScheduledBefore ( endTime ) ) { runOneTask ( ) ; ++ runCount ; } currentTime = endTime ; return runCount > 0 ; }
Run all runnables that are scheduled before the endTime .