Yanming Zhou 4 years ago committed by GitHub
parent d9983b32c1
commit 5efab340e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -279,8 +279,14 @@ abstract class PoolBase
try {
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
final ObjectName beanConfigName = new ObjectName("com.zaxxer.hikari:type=PoolConfig (" + poolName + ")");
final ObjectName beanPoolName = new ObjectName("com.zaxxer.hikari:type=Pool (" + poolName + ")");
ObjectName beanConfigName, beanPoolName;
if ("true".equals(System.getProperty("hikaricp.jmx.register2.0"))) {
beanConfigName = new ObjectName("com.zaxxer.hikari:type=PoolConfig,name=" + poolName);
beanPoolName = new ObjectName("com.zaxxer.hikari:type=Pool,name=" + poolName);
} else {
beanConfigName = new ObjectName("com.zaxxer.hikari:type=PoolConfig (" + poolName + ")");
beanPoolName = new ObjectName("com.zaxxer.hikari:type=Pool (" + poolName + ")");
}
if (register) {
if (!mBeanServer.isRegistered(beanConfigName)) {
mBeanServer.registerMBean(config, beanConfigName);

@ -96,6 +96,25 @@ public class TestMBean
finally {
System.clearProperty("com.zaxxer.hikari.housekeeping.periodMs");
}
System.setProperty("hikaricp.jmx.register2.0", "true");
try (HikariDataSource ds = new HikariDataSource(config)) {
getUnsealedConfig(ds).setIdleTimeout(3000);
TimeUnit.SECONDS.sleep(1);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName poolName = new ObjectName("com.zaxxer.hikari:type=Pool,name=testMBeanReporting");
HikariPoolMXBean hikariPoolMXBean = JMX.newMXBeanProxy(mBeanServer, poolName, HikariPoolMXBean.class);
assertEquals(0, hikariPoolMXBean.getActiveConnections());
assertEquals(3, hikariPoolMXBean.getIdleConnections());
}
finally {
System.clearProperty("hikaricp.jmx.register2.0");
}
}
@Test

Loading…
Cancel
Save