Skip to content

Commit

Permalink
fix when hikari pool is null
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Aug 22, 2020
1 parent 77c284c commit 6735097
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,23 @@ private boolean terminate(DataSource dataSource) {
private boolean terminateHikariDataSource(HikariDataSource dataSource) {
HikariPoolMXBean poolMXBean = dataSource.getHikariPoolMXBean();

//evict idle connections
poolMXBean.softEvictConnections();

if (poolMXBean.getActiveConnections() > 0 && retryTimes < MAX_RETRY_TIMES) {
logger.warn("Data source {} still has {} active connections, will retry in {} ms.", dataSource,
poolMXBean.getActiveConnections(), RETRY_DELAY_IN_MILLISECONDS);
return false;
}
if (poolMXBean != null) {
//evict idle connections
poolMXBean.softEvictConnections();

if (poolMXBean.getActiveConnections() > 0 && retryTimes < MAX_RETRY_TIMES) {
logger.warn("Data source {} still has {} active connections, will retry in {} ms.",
dataSource,
poolMXBean.getActiveConnections(), RETRY_DELAY_IN_MILLISECONDS);
return false;
}

if (poolMXBean.getActiveConnections() > 0) {
logger.warn("Retry times({}) >= {}, force closing data source {}, with {} active connections!", retryTimes,
MAX_RETRY_TIMES, dataSource, poolMXBean.getActiveConnections());
if (poolMXBean.getActiveConnections() > 0) {
logger.warn(
"Retry times({}) >= {}, force closing data source {}, with {} active connections!",
retryTimes,
MAX_RETRY_TIMES, dataSource, poolMXBean.getActiveConnections());
}
}

dataSource.close();
Expand Down

0 comments on commit 6735097

Please sign in to comment.