gpt4 book ai didi

java - 未收到 Apache HttpAsyncClient 响应

转载 作者:行者123 更新时间:2023-12-02 04:58:19 29 4
gpt4 key购买 nike

在我的 servlet 中,我正在执行以下代码:

RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build();
CloseableHttpAsyncClient client = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build();

try
{
client.start();

for (String request : preparedURLs)
{
client.execute(new HttpGet(request), new FutureCallback<HttpResponse>()
{
public void failed(Exception ex)
{
System.out.println("\n\nRequest Failed Due to : " + ex.getMessage());
}

public void completed(HttpResponse response)
{
System.out.println("\n\nRequest COMPLETED");
}

public void cancelled()
{
System.out.println("\n\nRequest CANCELLED");
}
});

System.out.println("\n\n" + request);
}
}
finally
{
System.out.println("\n*** Finally called ***\n\n");
client.close();
}

但我根本没有得到任何回应。以下内容打印在我的 catalina.out 中:

http://localhost:8080/servlet/?ps=true


http://localhost:8080/servlet/?ps=true


http://localhost:8080/servlet/?ps=false

*** Finally called ***

我写了这段代码,取 this以 apache 官方网站为例。

我只省略了闩锁部分。这与闩锁有关吗?

如果可以的话请解释一下失败的原因。

最佳答案

您删除的这个闩锁实际上是示例的同步部分。

异步客户端的想法是发出一些请求并等待其他线程上的响应。通过删除同步,执行直接传递到finally block ,而不是等待响应并关闭HttpAsyncClient。

为了让它恢复工作,请添加示例中的锁存代码。

关于java - 未收到 Apache HttpAsyncClient 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28545460/

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