【问题标题】:Spring boot + AWS Linux + Oracle databaseSpring Boot + AWS Linux + Oracle 数据库
【发布时间】:2019-04-03 02:30:06
【问题描述】:

我在 AWS Linux 上使用 JPA 开发了 Spring Boot REST API,并使用 Oracle11g 作为数据库,因为我们正在处理 Spring Boot,所以我们不必处理连接。

netstat -n | grep 1521   

当我触发此命令检查所有连接是否已关闭时,我可以看到许多连接处于CLOSE_WAIT 状态。
谁能建议Tomcat或Apache的应用程序或配置有什么问题?

application.properties

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

【问题讨论】:

  • 这样的问题究竟是如何获得投票的? Tomcat 或 Apache 的应用程序或配置有什么问题? - 这怎么可能?我们是心灵读者吗?如果你想检查一些代码或配置文件,那么至少你需要做的是发布它
  • @ScaryWombat 我也无法共享 apache 或 tomcat 的配置文件。我只是想知道是否有人遇到过在后台打开这么多 CLOSE_WAIT 实例的类似问题。

标签: java linux spring-boot amazon-ec2 oracle11g


【解决方案1】:

问题是 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);
    }

【讨论】:

  • 你认为我们可以在 Spring Boot 应用程序中编写这段代码吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-03
  • 2021-10-16
  • 2019-06-15
  • 2020-12-26
  • 2022-01-17
  • 1970-01-01
  • 2015-09-07
相关资源
最近更新 更多