Skip to content

Commit

Permalink
add lock to JdbcConnectionPools.close
Browse files Browse the repository at this point in the history
  • Loading branch information
loserwang1024 committed Jul 5, 2024
1 parent 2153502 commit e4745e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ public String getJdbcUrl(
}

public static void close() throws IOException {
if (instance != null) {
instance.pools.values().stream().forEach(HikariDataSource::close);
instance.pools.clear();
POOL_FACTORY_MAP.clear();
synchronized (instance.pools) {
if (instance != null) {
instance.pools.values().stream().forEach(HikariDataSource::close);
instance.pools.clear();
POOL_FACTORY_MAP.clear();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public HikariDataSource getOrCreateConnectionPool(
}
}

public static void close() throws IOException {
if (INSTANCE != null) {
INSTANCE.pools.values().stream().forEach(HikariDataSource::close);
INSTANCE.pools.clear();
public static synchronized void close() throws IOException {
synchronized (INSTANCE.pools) {
if (INSTANCE != null) {
INSTANCE.pools.values().stream().forEach(HikariDataSource::close);
INSTANCE.pools.clear();
}
}
}
}

0 comments on commit e4745e1

Please sign in to comment.