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 <ifedorenko@apache.org>
This commit is contained in:
Igor Fedorenko 2014-09-02 08:14:49 -04:00
parent 2909b5a329
commit a5b92f2d03
1 changed files with 12 additions and 12 deletions

View File

@ -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();
}
}
}