Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Created June 20, 2020 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackjutsu/61fbb7e6a4b44c4b1d10d44573472cf9 to your computer and use it in GitHub Desktop.
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
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