Java – monitoring dbcp2 connection pools using JMX

I read from the dbcp2 documentation that this new version supports JMX monitoring of connection pools, but I can't find any examples showing actual usage

I have a simple JDBC based Java application that uses dbcp2 to create a connection pool used by a simple query service. I want to use JMX to monitor these connections through another tool, such as visualvm The basicdatasource of dbcp2 has a method like setjmxname(). I don't see any usage and don't know how to use it

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

Any help in this regard will be greatly appreciated thank you!

Solution

I haven't found any documents, but I've found something by mining the source code

You just need to create BasicDataSource or BasicManagedDataSource objects as usual, and then call the setJmxName () method. Then, when you call the getconnection () method, the datasource will register itself with the MBean server of the platform and cancel the registration when you call the close () method

The JMX name "org. Apache. DBCP: datasource = mydbname" is set to be valid. An example of Apache for unit testing can be found here

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>