概述
Java and Simple Retry
This is really nice.
Add this in pom.xml
<dependency>
<groupId>net.jodah</groupId>
<artifactId>failsafe</artifactId>
<version>1.0.5</version>
</dependency>
I am retrying that on top of the result.
private RetryPolicy getPolicy()
{
RetryPolicy retryPolicy = new RetryPolicy();
retryPolicy.retryIf( result -> result.equals( false ) );
retryPolicy.withDelay( 10, TimeUnit.SECONDS );
retryPolicy.withMaxRetries( 3 );
return retryPolicy;
}
public boolean uploadFile( String bucketName, String key, String fileToUpload )
{
boolean result =
Failsafe.with( this.getPolicy() ).get( () -> this.uploadFileOnce( bucketName, key, fileToUpload ) );
return result;
}
Maybe it should be better in AKKA, crash and recover mode. But I do not have AKKA here, maybe this solution is simple and useful.
References:
https://github.com/jhalterman/failsafe#asynchronous-api-integration
最后
以上就是机灵黄豆为你收集整理的Java and Simple Retry的全部内容,希望文章能够帮你解决Java and Simple Retry所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复