http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/core/org.eclipse.smila.solr/code/为什么要对实例管理?看看wiki文档说明就知道了。
/*
HttpSolrServer is thread-safe and if you are using the following constructor,
you *MUST* re-use the same instance for all requests. If instances are created on
the fly, it can cause a connection leak. The recommended practice is to keep a
static instance of HttpSolrServer per solr server url and share it for all requests.
See https://issues.apache.org/jira/browse/SOLR-861 for more details
*/
goole翻译,我理解的大概意思是:HttpSolrServer是线程安全的,保持每台Solr服务器的的URL HttpSolrServer静态实例能防止连接泄漏,性能也有提升,节省了资源开销。
google上找来一个开源代码,虽然他们用的solr不是最新版4.0。但是模式可以借鉴。
看了看这个SolrServer Manager类的代码,我是觉得不错,就拿来使用了
发链接,不贴代码了,没有格式,太难看了
http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/core/
这个链接里的东西都是宝物哦,赶紧行动吧!
一个简单问答
stackoverflow - Solr - instantiate HttpSolrServer with Httpclient