谁能明白为什么 Tomcat 在我的连接池上超时?

问题描述 投票:0回答:1

我的 Springboot 应用程序中有一个连接池,并在 Application.properties 中进行以下设置:

// db user name, password, url here...
spring.datasource.tomcat.initial-size=15
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=100
spring.datasource.tomcat.max-idle=15
spring.datasource.tomcat.min-idle=8
spring.datasource.tomcat.default-auto-commit=true
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

暂时一切都好。但发生的情况是,每隔几个小时,就会出现问题,并且在尝试运行 JDBC 代码时出现此异常:
数据意外结束。

在其他类中,数据意外结束异常显示为 SQL 异常,但它是相同的消息。

如果我重新启动 Tomcat,JDBC 将再次正常工作......一段时间。

连接代码如下所示:

try
    (
            final Connection connection = dataSource.getConnection();
            final PreparedStatement statement = connection.prepareStatement(SQL_TO_RUN_HERE);
    )
    {
    .
    .
    .
    
    }

“dataSource”被注入到类中,并且是连接池实例。

另外,如果我根本不使用连接池而只使用

DriverManager.getConnection(...),
,那么它总是可以正常工作,没有任何问题。

任何人都可以看到哪些设置已关闭或者我可能需要将哪些设置添加到连接池设置中?

提前非常感谢,

java spring-boot jdbc connection-pooling
1个回答
0
投票

尝试增加 max-active 值,因为根据应用程序的并发要求,值 100 可能太低

© www.soinside.com 2019 - 2024. All rights reserved.