小编neo*_*mal的帖子

java 8中如何实现异步重试机制?

我正在使用 Java 8 Spring 启动。我有以下方法。

public hello() {
  try {
    // send message
  }
  catch(HttpClientErrorException e) {
     if (e.getRawStatusCode() == 401) {
          // I need to retry the same hello() method for three times as in 10sec, 20sec and 25sec.
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

我需要调用相同的方法三次,以便在遇到 catch 块时重试。我怎样才能异步执行此操作?

我找到了下面的代码,但它不起作用。

@Retryable( value = {RestClientException.class}, maxAttempts = 3, backoff = @Backoff(3000)) 
Run Code Online (Sandbox Code Playgroud)

感谢你的帮助。

asynchronous java-8 spring-retry spring-boot

2
推荐指数
1
解决办法
9563
查看次数

标签 统计

asynchronous ×1

java-8 ×1

spring-boot ×1

spring-retry ×1