Monitoring DBCP2 connection pool with JMX
Asked Answered
G

1

10

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!

Goldstein answered 25/1, 2016 at 16:50 Comment(2)
Improved the question format to make it a bit easier to understand. Added some resources pointing to the JDBC documentation for others to easier follow up on what the topic is focusing on.Lowdown
I had tons of issue with DBCP2 in Production with the high number of threads, I decided to use C3P0 which is working perfectly, plus it had a very good JMX implementation.Goldstein
P
10

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.

Pingpingpong answered 12/7, 2016 at 19:14 Comment(1)
The Object Name Syntax is described here: oracle.com/us/technologies/java/best-practices-jsp-136021.html.Cerell

© 2022 - 2024 — McMap. All rights reserved.