本文介绍了Tomcat JDBC池中没有足够的空闲连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下Tomcat JDBC连接设置:
Given the following Tomcat JDBC connection settings:
<Resource name="jdbc/pc4"
maxActive="200"
maxIdle="100"
minIdle="50"
initialSize="50"
maxWait="15000"
auth="Container"
type="javax.sql.DataSource"
username="....."
password="....."
testOnBorrow="true"
testWhileIdle="true"
validationQuery="select 1"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url="jdbc:mysql://server_address/db_name?autoReconnect=true&autoReconnectForPools=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&socketTimeout=300000" />
以下MySQL参数:
max_connections = 100000
wait_timeout = 31536000
interactive_timeout = 31536000
我希望连接池中始终有至少50个空闲连接。
I would expect there to be at least 50 idle connections in connection pool at all time.
但真正发生的是:服务器有50个连接一段时间后,所有的连接都死了,除了最后一个。
But what really happens is: there are 50 connections when the server started, after a while, all the connections die except the last one.
我的配置是否有错误?
环境:
- Linux 3.4 64位
- OpenJDK 7
- Tomcat 7
- MySQL 5.5
- Linux 3.4 64-bit
- OpenJDK 7
- Tomcat 7
- MySQL 5.5
推荐答案
我改变了配置,情况似乎有所改善,现在连接池中总有超过25个连接(但仍然不确定为什么)。
I changed the configuration and the situation seems to be improved, there are now always more than 25 connections in connection pool (still not sure why though).
<Resource name="jdbc/pc4"
maxActive="-1"
maxIdle="-1"
minIdle="20"
initialSize="20"
maxWait="-1"
auth="Container"
type="javax.sql.DataSource"
username="__"
password="__"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testOnBorrow="true"
testWhileIdle="true"
testOnReturn="true"
timeBetweenEvictionRunsMillis="60000"
minEvictableIdleTimeMillis="60000"
removeAbandoned="false"
validationQuery="SELECT 1;"
url="jdbc:mysql://__/__?autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&socketTimeout=72000000" />
这篇关于Tomcat JDBC池中没有足够的空闲连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!