SOLR-4791: Use URLClassLoader.close() to try to release jar files from URLClassLoader

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1480362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-05-08 17:21:46 +00:00
parent dcc27e14b6
commit e19e272d62
3 changed files with 13 additions and 2 deletions

View File

@ -580,6 +580,7 @@ public class CoreContainer
zkSys.close();
}
org.apache.lucene.util.IOUtils.closeWhileHandlingException(loader); // best effort
}
public void cancelCoreRecoveries() {

View File

@ -17,6 +17,7 @@
package org.apache.solr.core;
import java.io.Closeable;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@ -37,6 +38,7 @@ import org.apache.lucene.analysis.util.TokenizerFactory;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.analysis.util.WordlistLoader;
import org.apache.solr.common.ResourceLoader;
import org.apache.solr.handler.admin.CoreAdminHandler;
@ -68,7 +70,7 @@ import org.apache.solr.search.QParserPlugin;
/**
* @since solr 1.3
*/
public class SolrResourceLoader implements ResourceLoader
public class SolrResourceLoader implements ResourceLoader,Closeable
{
public static final Logger log = LoggerFactory.getLogger(SolrResourceLoader.class);
@ -206,7 +208,9 @@ public class SolrResourceLoader implements ResourceLoader
SolrException.log(log, "Can't add element to classloader: " + files[j], e);
}
}
return URLClassLoader.newInstance(elements, oldLoader.getParent());
ClassLoader oldParent = oldLoader.getParent();
IOUtils.closeWhileHandlingException(oldLoader); // best effort
return URLClassLoader.newInstance(elements, oldParent);
}
// are we still here?
return oldLoader;
@ -755,4 +759,9 @@ public class SolrResourceLoader implements ResourceLoader
}
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, builder.toString() );
}
@Override
public void close() throws IOException {
IOUtils.close(classLoader);
}
}

View File

@ -181,5 +181,6 @@ public class ResourceLoaderTest extends LuceneTestCase
// null file filter means accept all (making otherFile accessible)
loader.addToClassLoader("otherLib", null, false);
assertNotNull(loader.getClassLoader().getResource("otherFile"));
loader.close();
}
}