我使用jcabi方面重试到我的URL http://xxxxxx:8080/hello的连接,直到连接来了back.As,您知道jcabi的@ retry connection有两个字段尝试和延迟。
我想要执行类似于jcabi 上的min=60000尝试(12)=expiryTime(1 min=60000 millis)/delay(5 sec=5000 millis)的操作,this.The代码片段如下所示。
@RetryOnFailure(attempts = 12, delay = 5)
public String load(URL url) {
return url.openConnection().getContent();
}发布于 2016-09-25 00:29:12
您可以组合两个注释:
@Timeable(unit = TimeUnit.MINUTE, limit = 1)
@RetryOnFailure(attempts = Integer.MAX_VALUE, delay = 5)
public String load(URL url) {
return url.openConnection().getContent();
}@RetryOnFailure将永远重试,但@Timeable会立即停止它。
发布于 2016-09-24 13:11:35
您选择的库(jcabi)没有此特性。但是幸运的是,Spring批处理中非常方便的RetryPolicies已经被提取出来(因此您可以单独使用它们,而不需要批处理):
您可以在其中使用的许多类之一是TimeoutRetryPolicy:
RetryTemplate模板=新的RetryTemplate();
TimeoutRetryPolicy policy = new TimeoutRetryPolicy();
policy.setTimeout(30000L);
template.setRetryPolicy(policy);
Foo result = template.execute(new RetryCallback<Foo>() {
public Foo doWithRetry(RetryContext context) {
// Do stuff that might fail, e.g. webservice operation
return result;
}
});整个春重试项目非常容易使用,并且有很多特性,比如backOffPolicies、监听器等等。
https://stackoverflow.com/questions/39673618
复制相似问题