public static < T > T retryWithExponentialBackoff ( Retryable < T > runnable , int maxRetries ) throws InterruptedException , OperationRetryFailedException { int retry = 0 ; while ( retry < maxRetries ) { retry ++ ; try { return runnable . execute ( ) ; } catch ( OperationRequireRetryException e ) { // No-op. } catch ( InterruptedException e ) { throw e ; } if ( retry > 1 ) { long delay = ( long ) ( ( BACKOFF_BASE << retry ) * Math . random ( ) ) ; log . debug ( "Operation requested retry. Sleep for {} millis" , delay ) ; Thread . sleep ( delay ) ; } } throw new OperationRetryFailedException ( "Maximum number of operation retries reached" ) ; }
Retries passed operation with random exponential back off delay .