【发布时间】:2015-04-17 08:58:40
【问题描述】:
我在命令行程序中使用 ning AsyncHttpClient。我需要等待所有请求结束,这样我才能安全地在客户端上调用close()。挑战在于我从程序的许多不同部分提出了许多请求。下面剥离了自己的代码,显示了我从另一个请求的onCompleted 执行嵌套 HTTP 请求的一种情况:
final AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
Future<Response> f1 = asyncHttpClient.prepareGet(url).execute(
new AsyncCompletionHandler<Response>() {
public Response onCompleted(Response response)
throws Exception {
//Make more HTTP calls
Future f2 = asyncHttpClient.prepareGet(url).execute(...);
return response;
}
});
这只是一个示例代码。真正的代码更复杂,并且有更多的 HTTP 调用。在我为客户拨打 close() 之前,确保所有呼叫都完成的最佳方法是什么?
【问题讨论】:
-
你有没有想过这个问题?
标签: asynchttpclient ning