SolrJ Unterminated Thread
I'm running the following program. The main thread runs and terminates normally but the program continues to run because of a thread called pool-1开发者_JAVA技巧-thread-1, which never terminates. Can anyone suggest what is wrong with the code? The configuration files are all as supplied in the standard distribution of Solr.
package solrapp;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.core.CoreContainer;
public class SolrApp {
public static void main(String[] args) throws Exception {
CoreContainer coreContainer = new CoreContainer.Initializer().initialize();
SolrServer server = new EmbeddedSolrServer(coreContainer, null);
SolrQuery query = new SolrQuery("*:*");
QueryResponse response = server.query(query);
SolrDocumentList results = response.getResults();
System.out.println(results);
}
}
It appears that the CoreContainer
class has a method called shutdown
.
Although I haven't tried it myself, I would guess that adding the following line after printing out the results should stop all the threads:
coreContainer.shutdown();
My guess would be that the CoreContainer
is starting up a thread pool to accept queries, so one should tell the object that started up the pool to stop those threads so that all threads on the JVM can gracefully shutdown.
精彩评论