我希望使用HTTPClient运行线程安全的异步HTTP请求。但是我发现它不会遵循我的CONNECTION_TIMEOUT
参数。
代码是ColdFusion / Java混合编写的。
client = loader.create("org.apache.http.impl.nio.client.DefaultHttpAsyncClient").init();
CoreConnectionPNames = loader.create("org.apache.http.params.CoreConnectionPNames");
client.getParams()
.setIntParameter(JavaCast("string", CoreConnectionPNames.SO_TIMEOUT), 10)
.setIntParameter(JavaCast("string", CoreConnectionPNames.CONNECTION_TIMEOUT), 10);
client.start();
request = loader.create("org.apache.http.client.methods.HttpGet").init("http://www.google.com");
future = client.execute(request, javacast("null", ""));
try {
response = future.get();
}
catch(e any) {}
client.getConnectionManager().shutdown();
无论我为 CONNECTION_TIMEOUT 提供什么值,请求总是返回200 OK。请检查下面的输出。
- 如何设置有效的连接超时?
- CONNECTION_TIMEOUT 有用吗?
输出
200 OK http://www.google.com/
200 OK http://www.google.com/
[snip]
5 requests using Async Client in: 2308 ms