public long backoff(int attempt){
  long duration=base * (long)Math.pow(factor,attempt);
  if (jitter != 0) {
    double random=Math.random();
    int deviation=(int)Math.floor(random * jitter * duration);
    if ((((int)Math.floor(random * 10)) & 1) == 0) {
      duration=duration - deviation;
    }
 else {
      duration=duration + deviation;
    }
  }
  if (duration < 0) {
    duration=Long.MAX_VALUE;
  }
  return Math.min(Math.max(duration,base),cap);
}

public long backoff ( int attempt ) { long duration = base * ( long ) Math . pow ( factor , attempt ) ; if ( jitter != 0 ) { double random = Math . random ( ) ; int deviation = ( int ) Math . floor ( random * jitter * duration ) ; if ( ( ( ( int ) Math . floor ( random * 10 ) ) & 1 ) == 0 ) { duration = duration - deviation ; } else { duration = duration + deviation ; } } if ( duration < 0 ) { duration = Long . MAX_VALUE ; } return Math . min ( Math . max ( duration , base ) , cap ) ; }
return the duration ( in milliseconds ) for which you should backoff .
