gpt4 book ai didi

mysql - tomcat connectionpool mysql配置避免空闲连接超时

转载 作者:行者123 更新时间:2023-11-28 22:32:50 26 4
gpt4 key购买 nike

我正在使用 tomcat 7 和 tomcat jdbc 连接池来分配 mysql 连接。

在夜间,我们没有任何事件,因此所有连接空闲时间超过 8 小时,并被 mysql 删除。 (mysql 的 wait_timeout 默认值)。

我们使用以下池配置:

<Resource name="jdbc/dbName"
auth="Container"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
type="javax.sql.DataSource"
maxActive="50"
maxIdle="30"
maxWait="5000"
driverClassName="com.mysql.jdbc.Driver"
validationQuery="SELECT 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
username="xxx"
password="xxx"
url="jdbc:mysql://host:3306/xxx"/>

我期待 EvictionPolicy 在闲置连接被 MySql 关闭之前删除它们。不知何故,一天后我们得到以下异常:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed by the driver.

我想这个问题应该是jdbc连接池可以解决的,但是配置属性很多,我以前没有用过这个池。任何人都有一套很好的属性来配置池不抛出关闭的连接?

亲切的问候,

阿尔伯特

最佳答案

解决了。事实证明,这毕竟不是一个池化问题。我们一起使用 squeryl 和 lift,这不是一个令人满意的组合(目前)。连接在返回池之前关闭。放弃 lift 的数据库连接管理,转而使用 squeryl 解决了这个问题。

关于mysql - tomcat connectionpool mysql配置避免空闲连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6953762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com