我的数据库连接池使用以下配置。
使用HikariCP 1.4.0、jdk1.6.0_45和Oracle Express 11g,在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);
我得到这个堆栈跟踪:
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)
使用 JConsole 并附加到正在运行的进程。我看到以下 MBean:JMImplemtation、com.oracle.jdbc、com.sun.management、java.lang、java.nio、java.util.logging。
我没有看到任何与 Hikari 连接池相关的内容。
有什么建议我接下来可以尝试吗?
两件事情。有一个报告错误 https://github.com/brettwooldridge/HikariCP/pull/93就在两天前,针对 HikariCP 1.4.0 关于用户定义的池名称被忽略(并替换为自动生成的名称)的问题。此错误已修复,但您需要克隆存储库并自行构建,因为它要到下一个版本才会出现。
第二件事是,你需要设置registerMbeans
to true
。从编程上来说,这将是setRegisterMbeans(true)
。如果您运行现有的 1.4.0,您的用户定义名称将被忽略,但该池确实会被注册为 MBean。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)