On 6/26/2013 11:25 PM, Sandeep Gupta wrote: > To have singleton design pattern for SolrServer object creation, > I found that there are so many ways described in > http://en.wikipedia.org/wiki/Singleton_pattern > So which is the best one, out of 5 examples mentioned in above url, for web > application in general practice. > > I am sure lots of people (in this mailing list) will have practical > experience > as which type of singleton pattern need to be implement for creation of > SolrServer object.
I will admit that when I used the word "singleton" I honestly hadn't looked it up to see what it really meant. If you do use the full meaning of singleton, you can do this in any way you want. Perhaps a better thing to say is that you only need one SolrServer object for each base URL (host/port/core combination). Things are a little bit different when it comes to SolrCloud - you can use one CloudSolrServer object for the entire cloud, even if there are many collections and many servers. In my own SolrJ code, I create two HttpSolrServer objects within each of my homegrown "Core" objects. One of them is for operations against that specific Solr core, the other is for CoreAdmin operations. Because the URL for CoreAdmin operations is common to multiple cores, I create a static Map with those server objects so that my "Core" objects can share the SolrServer object used for CoreAdmin when they are on the same server machine. For the query side, if you're in a situation where you have one access point to your Solr installation (a load balancer in front of replicating Solr servers) and you only have one index, then you could create a single static SolrServer object for your entire application. Thanks, Shawn