Created
June 20, 2020 01:33
-
-
Save hackjutsu/61fbb7e6a4b44c4b1d10d44573472cf9 to your computer and use it in GitHub Desktop.
[Guava Retryer] Snippet for retrying by Guava Retryer https://github.com/rholder/guava-retrying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Callable<Boolean> callable = new Callable<Boolean>() { | |
public Boolean call() throws Exception { | |
return true; // do something useful here | |
} | |
}; | |
Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder() | |
.retryIfResult(Predicates.<Boolean>isNull()) | |
.retryIfExceptionOfType(IOException.class) | |
.retryIfRuntimeException() | |
.withStopStrategy(StopStrategies.stopAfterAttempt(3)) | |
.build(); | |
try { | |
retryer.call(callable); | |
} catch (RetryException e) { | |
e.printStackTrace(); | |
} catch (ExecutionException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment