当我执行以下命令时,在ubuntu上看到很多CLOSE_WAIT连接,其中20919是tomcat的pid。许多处于CLOSE_WAIT状态的套接字会导致大量打开文件吗?
sudo lsof -p 20919 | grep CLOSE_WAIT
下面是关闭客户请求的代码
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(30, TimeUnit.SECONDS);
builder.readTimeout(30, TimeUnit.SECONDS);
builder.writeTimeout(30, TimeUnit.SECONDS);
OkHttpClient client = builder.build();
String webServiceEndPoint = url;
Response response =null;
if (!url.matches("^(http|https)://.*$")) {
webServiceEndPoint = backendConfig.getWebServiceUri().concat(url);
}
Request request = new Request.Builder()
.url(webServiceEndPoint)
.method(method, getRequestBody(requestContext, method))
.headers(buildHeaders(headerBuilder))
.build();
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
if (isJsonObject(responseBody)) {
callback.onSuccess(JsonObjectBuilder.fromString(responseBody));
} else if (isJsonArray(responseBody)) {
callback.onSuccess(JsonObjectBuilder.arrayfromString(responseBody));
} else {
// logger.debug("couldn't determine response type [response : {}]", responseBody);
callback.onSuccess(responseBody);
}
} else {
callback.onError(responseBody, new SimpleStatusLine(response.code(), ""));
}
if(response!=null)response.body().close();
} catch (Exception e) {
callback.onFailure(e);
}finally{
LOG.debug("finally cleaning rsources");
if(response!=null)response.body().close();
client.connectionPool().evictAll();
}
这似乎无法清除CLOSE_WAIT状态。我正在将Okcat 3.8.1与tomcat 8一起使用