我是靠谱客的博主 机灵黄豆,最近开发中收集的这篇文章主要介绍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 and Simple Retry所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部