gpt4 book ai didi

java - Tomcat 7 - 忽略数据库连接池参数 (DBCP)

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:24:00 25 4
gpt4 key购买 nike

我们面临一个问题,即在 Tomcat 7 重启期间与数据库建立的连接数激增。

我们的配置如下,设置在 Tomcat 的 context.xml 中:

<Resource auth="Container"
driverClassName="oracle.jdbc.driver.OracleDriver"
initialSize="1"
maxActive="10"
maxAge="600000"
maxIdle="5"
maxOpenPreparedStatements="200"
maxWait="10000"
minEvictableIdleTimeMillis="60000"
minIdle="0"
name="jdbc/backoffice"
password="backoffice"
poolPreparedStatements="true"
rollbackOnReturn="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="6000000"
type="javax.sql.DataSource"
url="jdbc:oracle:thin:@127.0.0.1:1521:DATABASE"
username="backoffice"
validationQuery="SELECT SYSDATE FROM DUAL"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
/>

重启Tomcat后,打开的连接数接近700。重新部署 war (重命名为“.war_bk”再重命名回“.war”)解决了这个问题。

为什么会这样?我们可以做些什么不同的事情?

最佳答案

也为 maxConnLifetimeMillis 添加值

maxConnLifetimeMillis -1 The maximum lifetime in milliseconds of a connection. After this time is exceeded the connection will fail the next activation, passivation or validation test. A value of zero or less means the connection has an infinite lifetime.

maxTotal

maxTotal 8 The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.

您可以将 validationQuery 更改为更简单的查询

validationQuery="SELECT 1 FROM DUAL"

关于java - Tomcat 7 - 忽略数据库连接池参数 (DBCP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56023556/

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