我正在使用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();