DefaultHttpAsyncClient线程是否安全?为什么start()方法是强制性的?

时间:2013-05-30 00:05:01

标签: java http asynchronous client

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

0 个答案:

没有答案