Java trycatch使用重试Retryer
重试的工具类 Guava-retrying 依赖 <!-- https://mvnrepository.com/artifact/com.github.rholder/guava-retrying --> <dependency> <groupId>com.github.rholder</groupId> <artifactId>guava-retrying</artifactId> <version>2.0.0</version> </dependency> Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder() //抛出runtime异常、checked异常时都会重试,但是抛出error不会重试。 .retryIfException() //返回false也需要重试(可以根据返回值确定需不需要重试) .retryIfResult(Predicates.equalTo(false)) //重调策略 .withWaitStrategy(WaitStrategies.fixedWait(10, TimeUnit.SECONDS)) //尝试次数 .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); try { retryer.call