我觉得很简单。
代码:
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.closeExpiredConnections();
cm.closeIdleConnections(0, TimeUnit.SECONDS);
cm.setDefaultMaxPerRoute(50);
HttpHost localhost = new HttpHost(proxyStr, 80);
cm.setMaxPerRoute(new HttpRoute(localhost), 50);
HttpHost proxy = new HttpHost(ip, port);
routePlanner = new DefaultProxyRoutePlanner(proxy);
httpclient = HttpClients.custom()
.setConnectionManager(cm)
.setRetryHandler(new DefaultHttpRequestRetryHandler(0, true))
.setDefaultCookieStore(cookieStore)
.setRoutePlanner(routePlanner)
.setConnectionReuseStrategy(new NoConnectionReuseStrategy())
.build();
HttpPost httpPost = new HttpPost("https://*******);
List<NameValuePair> data = new ArrayList<NameValuePair>();
data.add(new BasicNameValuePair("DATA1", ***));
data.add(new BasicNameValuePair("DATA2", ***));
try {
httpPost.setEntity(new UrlEncodedFormEntity(data, HTTP.ISO_8859_1));
} catch (Exception e) {
}
CloseableHttpResponse response2 = null;
try {
response2 = httpclient.execute(httpPost);
} catch(Exception e)...
错误:
Jan12, 2018 8:43:40AMorg.apache.http.impl.execchain.RetryExec执行INFO:处理{tls}请求时捕获的I/O异常(java.net.SocketException)-
Jan12, 2018 8:43:40AMorg.apache.http.impl.execchain.RetryExec执行信息:重试对{tls}的请求-
2018年1月12日上午8:45:14组织。阿帕奇。http。impl。execchain。RetryExec执行信息:处理对{tls}的请求时捕获到I/O异常(org.apache.http.NoHttpResponseException)-
我已经扩展了抛出异常的功能,但我不能抓住它们。
我认为,这是因为它们是中断。
供您参考:
约25个线程使用该代码。一个错误关闭一个线程。如果Thread闭合,我无法检查=/
所以25个错误和我的程序卡住了...
希望有人知道如何解决这个问题=/
关于(https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/execchain/RetryExec.html)的信息
我要说的是,这个中断/异常是由httpclient引发的。执行(httpPost)
稍后我可以尝试修复,并会通知您。