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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With