java - HikariCP 连接池立即创建 100 个连接

标签 java mysql database-connection connection-pooling

我有这段使用 HikariCP 连接池的代码:

config.setMaximumPoolSize(100);
config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
config.addDataSourceProperty("serverName", hostname);
config.addDataSourceProperty("port", portnumber);
config.addDataSourceProperty("databaseName", dbname);
config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password);
config.setConnectionTimeout(30000);
config.setInitializationFailFast(false);
pooledDataSource = new HikariDataSource(config);

我通过发出命令“Show Processlist”监视 mysql 中的连接,我看到在以下行之后创建了 100 个连接:

pooledDataSource = new HikariDataSource(config);

...运行。我确定这不会发生,对吧?它应该稍后在我执行 pooledDataSource.getConnection() 时创建连接。

我做错了什么?为什么它立即创建 100 个连接??

最佳答案

默认情况下,HikariCP 作为固定大小的池运行。您需要设置 minimumIdle。就是这样。

来自 minimumIdle 的文档:

This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. If the idle connections dip below this value, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize

关于java - HikariCP 连接池立即创建 100 个连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27396725/

相关文章:

java - 为什么 minHeight 属性在 WebView Android 中不起作用?

mysql - 使用 shell 脚本备份 Mysql 数据库 - 绑定(bind)地址设置为 localhost

oracle11g - IJ000604 : Throwable while attempting to get a new connection: null: javax. 资源.ResourceException:无法创建连接

数据源 : SELECT 1 or something better? 中的 MySQL 连接有效性测试

java - HttpURLConnection 实现中的 "Socket sharing"

java - Java导入包的算法

java - 如何设置listgrid过滤器按钮属性? - 智能网关

MySQL - 包括日期的零计数

mysql - 使用 LEFT JOIN 和 SELF JOIN 以及聚合函数计算 acceptance_ratio

c# - 我的数据库连接关闭了吗? (Linq to Sql)