From a5b92f2d0307fcdccedd9553d1063196eeff5994 Mon Sep 17 00:00:00 2001 From: Igor Fedorenko Date: Tue, 2 Sep 2014 08:14:49 -0400 Subject: [PATCH] cleanup: release artifact resolver resources more eagerly Set resolver executor thread context classloader to null by default. This allows collection of class realms that triggered thread creation (one of plugin realms, typically). Use Disposable#dispose to shutdown resolver executor server, remove now redundant #finilaze() implementation. Signed-off-by: Igor Fedorenko --- .../resolver/DefaultArtifactResolver.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index f5a2349353..17ca48724d 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -60,6 +60,7 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.LocalRepositoryManager; @@ -71,7 +72,7 @@ import org.eclipse.aether.resolution.ArtifactResult; */ @Component( role = ArtifactResolver.class ) public class DefaultArtifactResolver - implements ArtifactResolver + implements ArtifactResolver, Disposable { @Requirement private Logger logger; @@ -120,17 +121,6 @@ public class DefaultArtifactResolver } } - @Override - protected void finalize() - throws Throwable - { - if ( executor instanceof ExecutorService ) - { - ( (ExecutorService) executor ).shutdown(); - } - super.finalize(); - } - private RepositorySystemSession getSession( ArtifactRepository localRepository ) { return LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem ); @@ -571,6 +561,7 @@ public class DefaultArtifactResolver { Thread newThread = new Thread( GROUP, r, "resolver-" + THREAD_NUMBER.getAndIncrement() ); newThread.setDaemon( true ); + newThread.setContextClassLoader( null ); return newThread; } } @@ -640,4 +631,13 @@ public class DefaultArtifactResolver } + @Override + public void dispose() + { + if ( executor instanceof ExecutorService ) + { + ( (ExecutorService) executor ).shutdownNow(); + } + } + }