2016-11-24 47 views
2

我試圖記錄當前活動連接的數量。我使用com.zaxxer.hikari.HikariJNDIFactory作爲我的數據源工廠。如何獲取HikariCP的活動連接數

final Context context = new InitialContext(); 
HikariConfig hikariConfig = new HikariConfig(); 
hikariConfig.setDataSource((DataSource) ((Context)context.lookup("java:comp/env")).lookup("jdbc/mydb")); 
HikariPool hikariPool = new HikariPool(hikariConfig); 
LOGGER.log(Level.INFO, "The count is ::" + hikariPool.getActiveConnections()); 

但它拋出以下異常:

java.lang.RuntimeException: java.lang.NullPointerException 
     at com.zaxxer.hikari.util.PoolUtilities.createInstance(PoolUtilities.java:105) 
     at com.zaxxer.hikari.metrics.MetricsFactory.createMetricsTracker(MetricsFactory.java:34) 
     at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:131) 
     at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:99) 
     at com.something.servlet.HikariConnectionCount.doGet(HikariConnectionCount.java:35) 

哪裏HikariConnectionCount.java是我寫

文件

回答

相關問題