由于这么多天我们正面临close_wait连接的问题。我怀疑是不是所有与该特定服务器的连接都进入了近距离等待。如果它本来是代码问题那么这个问题应该是我正在与服务器建立的每个连接。目标服务器是apache服务器,源服务器是glassfish。我还根据这篇文章添加了用于关闭连接的标题。http://www.michaelprivat.com/?p=63但是没有运气我发布了用于与目标服务器建立连接的代码。在建立连接时是否有任何问题?
public String Consumer(String userId, String Type) throws IOException {
CloseableHttpClient hc = HttpClients.createDefault();
try {
String response = null;
ResponseHandler<String> res = new BasicResponseHandler();
HttpPost postMethod = new HttpPost("http://IP and port of th target server/PolicyService.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userId", userId));
nameValuePairs.add(new BasicNameValuePair("Type", Type));
nameValuePairs.add(new BasicNameValuePair("token", Token));
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
postMethod.addHeader("Connection", "close");
response = hc.execute(postMethod, res);
return response;
} catch (HttpResponseException g) {
logger.error("Exception occurred of type: " , g);
return "";
} catch (UnsupportedEncodingException e) {
logger.error("Exception occurred of type: " , e);
return "";
} catch (ClientProtocolException e) {
logger.error("Exception occurred of type: " , e);
return "";
} catch (IOException e) {
logger.error("Exception occurred of type: " , e);
return "";
}
finally{
hc.close();
}
}
每次我都要重新启动服务器来刷新这个连接。有没有sugestions?