tomcat中数据库(mysql)连接池中最高连接参数设置
<Resource name="jdbc/demo"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
maxActive="1000"
maxIdle="1000"
minIdle="300"
maxWait="10000"
initialSize="300"
removeAbandonedTimeout="60"
removeAbandoned="true"
logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jmxEnabled="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="demo"
password="xxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/demo?useUnicode=true&useOldAliasMetadataBehavior=true"/>
最高连接数的设置(maxActive="1000")与mysql的参数相关,如果参数值高于mysql的最高连接数参数,则tomcat启动的时候会报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
mysql的最高连接数参数,
在mysql中执行 show variables like '%connections%'; 可以看到
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| max_connections | 1024 |
| max_user_connections | 0 |
+----------------------+-------+
2 rows in set (0.03 sec)
扫描二维码关注公众号,回复:
599471 查看本文章
其中 max_connections 就是mysql数据库的最高连接数。
打开mysql的配置文件(/etc/mysql/my.cnf),找到
#max_connections = 100
修改为
max_connections = 1024
1024是你要设置的最高连接数。