以下是从 PoolingNHttpClientConnectionManager 请求 NHttpClientConnection 的代码。调用 connFuture.get() 无法返回。有谁知道为什么?我正在使用 HttpAsyncClient 库 httpasyncclient-4.0.1.jar
static NHttpClientConnection httpConn = null;
public static void testOne() throws Exception {
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(ioReactor);
connManager.setMaxTotal(100);
long connectTimeout=1;
long leaseTimeout=4;
TimeUnit timeUnit = TimeUnit.SECONDS;
Object state = null;
HttpRoute route = new HttpRoute(new HttpHost("www.google.com", 80));
Future<NHttpClientConnection> connFuture = connManager.requestConnection(route, state, connectTimeout, leaseTimeout, timeUnit,
new FutureCallback<NHttpClientConnection>() {
public void completed(final NHttpClientConnection c) {
System.out.println("completed");
httpConn = c;
}
public void failed(final Exception ex) {
System.out.println("failed");
}
public void cancelled() {
System.out.println("cancelled");
}
} );
System.out.println("Step3");
connFuture.get(); // Failed to return
System.out.println("Done");
}