private void waitIfNeeded ( ) { // Calculate elapsed milliseconds long elapsed = System . currentTimeMillis ( ) - lastReqTime ; // If enough time has elapsed, no need to wait if ( elapsed >= interval ) { return ; } // If not enough time was elapsed, wait the remainder long toWait = interval - elapsed ; try { Thread . sleep ( toWait ) ; } catch ( InterruptedException ie ) { LOGGER . warn ( "Interrupted Exception thrown while politely waiting for remainder of interval" , ie ) ; } }
Wait if required .