Skip to content

Commit

Permalink
fix non_heap mem leak while use jdbc catalog and metadata cache auto …
Browse files Browse the repository at this point in the history
…refresh
  • Loading branch information
cambyzju committed Dec 23, 2024
1 parent 6403b3c commit 53c5cea
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

@Getter
Expand All @@ -57,6 +58,8 @@ public abstract class JdbcClient {
private static final int HTTP_TIMEOUT_MS = 10000;
protected static final int JDBC_DATETIME_SCALE = 6;

private static final Map<URL, ClassLoader> classLoaderMap = new ConcurrentHashMap<>();

private String catalogName;
protected String dbType;
protected String jdbcUser;
Expand Down Expand Up @@ -154,11 +157,16 @@ private void initializeDataSource(JdbcClientConfig config) {
}
}

private void initializeClassLoader(JdbcClientConfig config) {
private synchronized void initializeClassLoader(JdbcClientConfig config) {
try {
URL[] urls = {new URL(JdbcResource.getFullDriverUrl(config.getDriverUrl()))};
ClassLoader parent = getClass().getClassLoader();
this.classLoader = URLClassLoader.newInstance(urls, parent);
if (classLoaderMap.containsKey(urls[0])) {
this.classLoader = classLoaderMap.get(urls[0]);
} else {
ClassLoader parent = getClass().getClassLoader();
this.classLoader = URLClassLoader.newInstance(urls, parent);
classLoaderMap.put(urls[0], this.classLoader);
}
} catch (MalformedURLException e) {
throw new RuntimeException("Error loading JDBC driver.", e);
}
Expand Down

0 comments on commit 53c5cea

Please sign in to comment.