简体   繁体   中英

Monitoring DBCP2 connection pool with JMX

I read from DBCP2 documentation that this new version supports JMX monitoring for connection pool, but I couldn't find any example which shows actual usage.

I have a simple JDBC based java application which uses dbcp2 to create a connection pool which is used by a simple query service, and I want to monitor these connection via another tool like VisualVM using JMX. DBCP2's BasicDataSource has methods like setJmxName() which I don't see any usage for that, and don't know how to use it.

If someone is not familiar with JDBC, you can read about it here .

Any help on this will be appreciated. Thanks!

I haven't found any documentation either, but I have figured a few things out by digging through the source code.

You just need to create a BasicDataSource or BasicManagedDataSource object, like you normally would, and then call the setJmxName() method. The DataSource will then register itself with the platform's MBean server when you call the getConnection() method and unregister itself when you call the close() method.


Setting a JMX name of "org.apache.dbcp:DataSource=mydbname" works, an example Apache uses for unit tests can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM