Skip to content

Commit

Permalink
Close classloader on release
Browse files Browse the repository at this point in the history
  • Loading branch information
blindpirate committed Aug 24, 2019
1 parent 07e3e0d commit 3c69c4c
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class DefaultClassLoaderCache implements ClassLoaderCacheInternal, Stoppa
private final Map<ClassLoaderId, CachedClassLoader> byId = Maps.newHashMap();
private final Map<ClassLoaderSpec, CachedClassLoader> bySpec = Maps.newHashMap();
private final Set<ClassLoaderId> usedInThisBuild = Sets.newHashSet();
private final Set<CachedClassLoader> released = Sets.newHashSet();
private final ClasspathHasher classpathHasher;
private final HashingClassLoaderFactory classLoaderFactory;

Expand Down Expand Up @@ -75,6 +76,7 @@ public ClassLoader get(ClassLoaderId id, ClassPath classPath, @Nullable ClassLoa

if (cachedLoader != null) {
LOGGER.debug("Releasing previous classloader for {}", id);
released.add(cachedLoader);
cachedLoader.release(id);
}
return newLoader.classLoader;
Expand Down Expand Up @@ -140,6 +142,9 @@ public void stop() {
for (CachedClassLoader cachedClassLoader : byId.values()) {
ClassLoaderUtils.tryClose(cachedClassLoader.classLoader);
}
for (CachedClassLoader cachedClassLoader : released) {
ClassLoaderUtils.tryClose(cachedClassLoader.classLoader);
}
byId.clear();
bySpec.clear();
usedInThisBuild.clear();
Expand Down

0 comments on commit 3c69c4c

Please sign in to comment.