Java 故障保护RetryPolicy-从SupplySync引发异常

Java 故障保护RetryPolicy-从SupplySync引发异常,java,asynchronous,completable-future,retrypolicy,java-failsafe,Java,Asynchronous,Completable Future,Retrypolicy,Java Failsafe,我正在实施重试策略。基本上,我想做的是在一个单独的线程上重试POST请求。我正在使用jalterman()提供的故障保护,这是我的代码 Failsafe.with(retryPolicy).with(executor).future(() -> CompletableFuture.supplyAsync(() -> { try { CloseableHttpResponse response = client.execute(h

我正在实施重试策略。基本上,我想做的是在一个单独的线程上重试POST请求。我正在使用jalterman()提供的故障保护,这是我的代码

Failsafe.with(retryPolicy).with(executor).future(() -> CompletableFuture.supplyAsync(() -> {
            try {
                CloseableHttpResponse response = client.execute(httpPost);
                httpPost.releaseConnection();
                client.close();
                return response;
            } catch (IOException e) {
                return null;
            }
        }).thenApplyAsync(response -> "Response: " + response)
          .thenAccept(System.out::println));
我不想抓住这里的例外。它由重试策略处理。当前不会重试,因为我在这里捕获了异常。是否有方法从“SupplySync”引发异常,以便由重试策略处理? 谢谢
谢谢

CompletionStage API提供了几种不同的方法来处理和处理未检查的异常。但在你的情况下,你得到的是一个检查异常,你是运气不好。你要么处理好它,要么把它朝着打电话的人扔出去。如果你喜欢后一种方法,这里有一种方法

Failsafe.with(retryPolicy).with(executor).future(() -> CompletableFuture.supplyAsync(() -> {
            try {
                // Remainder omitted
                return response;
            } catch (IOException e) {
                throw new CompletionException(e);
            }
        }).thenApplyAsync(response -> "Response: " + response)
          .thenAccept(System.out::println));