我正在这个软件栈上运行Scala应用程序:
Mac OS X 10.6.8 Snow Leopard
MySQL 5.1.46
Java 1.6.0_65
Scala 2.11.2
ConnectorJ 5.1.33
HikariCP 2.1.0
Slick 2.1.0
我不明白为什么MySQL的开放连接在关闭Scala应用程序之后仍然保持开放。唯一正确的方面是,Threads_connected从16降到1(这是我执行“显示状态”命令的控制台。
mysql> show status like '%onn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 0 |
| Connections | 77 |
| Max_used_connections | 19 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 1 |
+--------------------------+-------+
7 rows in set (0.00 sec)
奇怪的是,每次运行该应用程序时,我总是看到连接池(HikariCP maximumPoolSize)中设置的最大打开连接数将打开到DB的连接,因此我可以声明连接从未返回到连接池以供重用。
根据光滑的文档
db withSession { implicit session =>
/* entering the scope, getting 1 conn from the pool */
/*
do something within the session using the connection I've gotten
*/
}
/* here I'm out of the 'withSession' scope, and the
connection should be released */
将在输入其作用域时从池中获取连接,并将其释放出范围。
我是做错了什么,还是在这个软件栈上对连接池的使用做错了什么?
发布于 2014-11-01 19:34:40
Connections
是自上次启动mysqld以来进行了多少次连接尝试的计数器。此计数器总是增加;当连接结束时,它不会减少。
这个计数器不是当前连接的数量--这是Threads_connected
。
https://stackoverflow.com/questions/26691092
复制相似问题