使用guava-retrying进行重试

maven依赖


      com.github.rholder
      guava-retrying
      2.0.0
    

使用

Callable callable = new Callable() {
    public Boolean call() throws Exception {
        return true; // do something useful here
    }
};

Retryer retryer = RetryerBuilder.newBuilder()
        .retryIfResult(Predicates.isNull())
        .retryIfExceptionOfType(IOException.class)
        .retryIfRuntimeException()
        .withStopStrategy(StopStrategies.stopAfterAttempt(3))
        .build();
try {
    retryer.call(callable);
} catch (RetryException e) {
    e.printStackTrace();
} catch (ExecutionException e) {
    e.printStackTrace();
}

docs

  • guava-retrying

你可能感兴趣的:(guava)