Get number of free connections in connection pool

2019-03-01 10:06发布

In my project Spring manages connection pool with org.apache.commons.dbcp.BasicDataSource class. Is possible to get how many connections are free or used in current time?

Thanks.

2条回答
别忘想泡老子
2楼-- · 2019-03-01 10:54

To get an instance of BasicDataSource you can use JMX and access the exposed beans. For example you can use Java Visual VM which is bundled with JDK since version 6, update 7. Of course you must install the MBeans plugin.

查看更多
孤傲高冷的网名
3楼-- · 2019-03-01 10:57

From the javadocs, you should be able to read this from the getNumIdle() and getNumActive() methods, if you can get an instance of the BasicDataSource.

查看更多
登录 后发表回答