Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HikariCP 1.4.0 MBean InstanceNotFoundException

I am using the following configuration for my database connection pool. Using HikariCP 1.4.0, jdk1.6.0_45 and Oracle Express 11g, running on Windows 7.

HikariConfig config = new HikariConfig();
config.setDataSourceClassName("oracle.jdbc.pool.OracleDataSource");
config.addDataSourceProperty("serverName", "localhost");
config.addDataSourceProperty("url", "jdbc:oracle:thin:@localhost:1521:XE");
config.addDataSourceProperty("user", "bob");
config.addDataSourceProperty("password", "bob1");
config.setPoolName("steve");

HikariDataSource ds = new HikariDataSource(config);

// do some inserts and reads here ... works great

MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName poolName = new ObjectName("com.zaxxer.hikari:type=Pool (steve)");

Integer idleConnections = (Integer) mBeanServer.getAttribute(poolName, "IdleConnections");

System.out.println("Number of Idle Connections : " + idleConnections);          

I get this stack trace:

javax.management.InstanceNotFoundException: com.zaxxer.hikari:type=Pool (steve)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:639)

Using JConsole and attaching to the running process. I see the following MBeans: JMImplemtation, com.oracle.jdbc, com.sun.management, java.lang, java.nio, java.util.logging.

I am not seeing anything related to a Hikari connection pool.

Any suggestions what I can try next?

like image 469
stevencpt Avatar asked Jun 20 '14 08:06

stevencpt


1 Answers

Two things. There was a bug reported against HikariCP 1.4.0 just two days ago regarding user-defined pool names being ignored (and replaced with the auto-generated name). This bug is fixed, but you need to clone the repository and build it yourself, as it will not appear until the next release.

Second thing is, you need to set registerMbeans to true. Programmatically, this would be setRegisterMbeans(true). If you run the existing 1.4.0, your user-defined name will be ignored, but the pool will indeed be registered as an MBean.

like image 142
brettw Avatar answered Oct 31 '22 13:10

brettw