5

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?

Vito Gentile
  • 13,336
  • 9
  • 61
  • 96
stevencpt
  • 53
  • 3

2 Answers2

7

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.

brettw
  • 10,664
  • 2
  • 42
  • 59
  • 2
    Something that might be obvious to some, the ```setRegisterMBeans(true)``` should called on the ```config``` and not on the HikariDataSource ```ds``` (because it will have no effect). – Jeremy Chone Apr 15 '15 at 22:43
  • 2
    That's not quite true. If you use a HikariConfig object, it must be set on that object. If you construct a HikariDataSource directly, without a HikariConfig, you can call ``setRegisterMBeans(true)`` on the HikariDataSource. When *not* using a HikariConfig, configuration set on the HikariDataSource before the first call to ``getConnection()`` will be honored. – brettw Apr 17 '15 at 00:00
  • @brettw wrong, I just tried it setting it to the DataSource and it does not work, but it does when setting to the config. – Alpha2k Apr 05 '18 at 23:45
0

The problem is with Hikari config, you need to check the agent jar.