我正在使用 Apache 的HttpAsyncClient库。我不明白几件事:
1)DefaultHttpAsyncClient
线程安全吗?我可以重复使用相同的客户端实例来发出多个并发请求吗?
2) 为什么我需要先向start()
客户提出请求?
HttpGet httpGet = new HttpGet("http://www.google.com");
DefaultHttpAsyncClient client = new DefaultHttpAsyncClient();
client.start(); // If the client is not started, the request will never be made
Future<HttpResponse> future = client.execute(httpGet, new FutureCallback<HttpResponse>() {
public void failed(Exception arg0) {
}
public void completed(org.apache.http.HttpResponse arg0) {
}
public void cancelled() {
}
});
HttpResponse httpResponse = future.get();