Skip to content

Commit

Permalink
Fix classNotFoundError in the caffee removal listener
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqi1129 committed Mar 19, 2024
1 parent 0544f2a commit 8e2bb8c
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ public class CachedClientPool implements ClientPool<IMetaStoreClient, TException
this.clientPoolCache =
Caffeine.newBuilder()
.expireAfterAccess(evictionInterval, TimeUnit.MILLISECONDS)
.removalListener((ignored, value, cause) -> ((HiveClientPool) value).close())
.removalListener(
(ignored, value, cause) -> {
// Set the class loader to the isolated class loader.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread()
.setContextClassLoader(CachedClientPool.class.getClassLoader());
try {
((HiveClientPool) value).close();
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
})
.scheduler(Scheduler.forScheduledExecutorService(scheduler))
.build();
}
Expand Down Expand Up @@ -136,6 +147,13 @@ private static ThreadFactory newDaemonThreadFactory() {

public void close() {
clientPoolCache.invalidateAll();

// Let the remove listener to close the HiveClientPool first then close the class loader.
try {
Thread.sleep(500);
} catch (Exception e) {
// Ignore
}
scheduler.shutdownNow();
}
}

0 comments on commit 8e2bb8c

Please sign in to comment.