gpt4 book ai didi

java - 使用 HttpAsyncClients 设置重试次数

转载 作者:行者123 更新时间:2023-12-01 23:22:00 25 4
gpt4 key购买 nike

使用典型的 HttpAsyncClients 示例:

public class AsyncClientHttpExchange {

public static void main(final String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
HttpGet request = new HttpGet("http://httpbin.org/get");
Future<HttpResponse> future = httpclient.execute(request, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}
}

如何设置无响应时的重试次数?我可以看到 5 个。

使用httpClientBuilder,有setRetryHandler:

httpClientBuilder.setRetryHandler(new MyRequestRetryHandler(_maxRetryCount));

HttpAsyncClients 是怎么回事?

最佳答案

HttpAsyncClient 4.x 不支持自动重新执行请求。此功能计划在 HttpAsyncClient 5.0 中使用

关于java - 使用 HttpAsyncClients 设置重试次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42554711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com