我已经在AWSLinux上用JPA开发了Spring Boot REST API,Oracle11g
作为数据库,当我们处理Spring Boot时,我们不必考虑连接。
netstat -n | grep 1521
当我触发这个命令来检查是否所有连接都已关闭时,我可以看到许多连接都处于CLOSE_WAIT
状态
有人能提出Tomcat或Apache的应用程序或配置是否有问题吗?
应用程序属性
spring.datasource.remove-abandoned=true
spring.datasource.remove-abandoned-timeout=30
spring.datasource.max-active=50
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10
spring.datasource.max-wait=10000
问题是HttpResponse没有关闭,为了解决这个问题,我使用了HttpClientUtils.closeQuietly,请参阅以下内容:
HttpResponse response = null;
try {
response = client.execute(createHttpRequest(url, timeOut));
StringBuilder result = new StringBuilder();
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
}
return result;
} catch (org.apache.http.conn.HttpHostConnectException e) {
throw new HostUnreachableException(e);
} finally {
HttpClientUtils.closeQuietly(response);
}