我正在使用poolighttpclientconnectionmanager,但是第一次url调用我有1000ms的响应,但是下一次调用时间减少为200ms,300ms,500ms?
初始化:
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
// Increase max total connection
connManager.setMaxTotal(maxTotalConnections);
// Increase default max connection per route
connManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
// config timeout
RequestConfig config = RequestConfig.custom().setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(waitTimeout).setSocketTimeout(readTimeout).build();
String proxyH = System.getProperty("https.proxyHost");
int proxyP = Integer.parseInt(System.getProperty("https.proxyPort"));
CloseableHttpClient httpClient = HttpClients.custom().setKeepAliveStrategy(keepAliveStrategy).setConnectionManager(connManager)
.setDefaultRequestConfig(config).setProxy(new HttpHost(proxyH, proxyP)).build();
发送邮件:
try {
StringEntity requestEntity = new StringEntity(this.reqData, DEFAULT_CHARSET);
postMethod = new HttpPost(url);
postMethod.setEntity(requestEntity);
response = execute(postMethod);
int statusCode = response.getStatusLine().getStatusCode();
SimpleHttpResponse simpleResponse = new SimpleHttpResponse();
simpleResponse.setStatusCode(statusCode);
HttpEntity entity = response.getEntity();
if (entity != null) {
String ctype = "application/json; charset=UTF-8";
String charset = getResponseCharset(ctype);
String content = EntityUtils.toString(entity, charset);
simpleResponse.setContent(content);
}
EntityUtils.consume(entity);
String respData = simpleResponse.getContent();
} catch (Exception e) {
e.printStackTrace();
} finally {
postMethod.releaseConnection();
if (response != null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
谢谢你的意见。请帮帮我!
暂无答案!
目前还没有任何答案,快来回答吧!