com.github.dennisit.vplus.data.utils.RetryUtils Maven / Gradle / Ivy
package com.github.dennisit.vplus.data.utils;
import com.github.rholder.retry.*;
import com.google.common.base.Predicates;
import java.util.concurrent.TimeUnit;
public class RetryUtils {
/**
* 测试过程中发现经常100ms内不能返回, 所以增加了2次50ms的重试
*/
private Retryer retryer = RetryerBuilder.newBuilder()
.retryIfException()
.retryIfResult(Predicates.notNull())
.withBlockStrategy(BlockStrategies.threadSleepStrategy())
.withStopStrategy(StopStrategies.stopAfterAttempt(2))
.withWaitStrategy(WaitStrategies.fixedWait(50, TimeUnit.MILLISECONDS))
.build();
}