我是靠谱客的博主 机灵黄豆,这篇文章主要介绍Java and Simple Retry,现在分享给大家,希望可以做个参考。

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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(138)

评论列表共有 0 条评论

立即
投稿
返回
顶部