TL; DR - SolrJ连接到SolrCloud或独立Solr实例时应该如何处理连接?
给出Apache SolrJ clint的以下Spring-bean配置:
<!-- SolrCloud client connector overrides the default standalone Solr instance connector -->
<bean id="SolrClient" class="org.apache.solr.client.solrj.impl.CloudSolrClient">
<constructor-arg index="0" value="${solr.zkHosts}"/>
<property name="defaultCollection" value="${solr.collection}"/>
</bean>
我从单独的配置类中建立一个SolrClient连接,如下所示:
SolrClient solrClient = config.getSolrClient();
solrClient.ping();
然后我打电话给
finally{
if(solrClient == null){
solrClient.close();
}
}
当我尝试再次调用该方法时,我得到以下异常:
Caused by: org.apache.solr.client.solrj.SolrServerException: java.lang.IllegalStateException: Connection pool shut down
at org.apache.solr.client.solrj.impl.LBHttpSolrClient.doRequest(LBHttpSolrClient.java:410)
at org.apache.solr.client.solrj.impl.LBHttpSolrClient.request(LBHttpSolrClient.java:325)
at org.apache.solr.client.solrj.impl.CloudSolrClient.sendRequest(CloudSolrClient.java:1100)
at org.apache.solr.client.solrj.impl.CloudSolrClient.requestWithRetryOnStaleState(CloudSolrClient.java:871)
at org.apache.solr.client.solrj.impl.CloudSolrClient.request(CloudSolrClient.java:807)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:150)
at org.apache.solr.client.solrj.SolrClient.ping(SolrClient.java:927)
通过阅读SolrJ文档,close()执行以下操作:
Closes this stream and releases any system resources associated with it.
似乎在连接上调用close会逐字地关闭线程池,从而阻止将来的连接......使用SolrJ处理与Solr的多个连接的正确方法是什么?