On 7/1/2021 6:36 PM, Reej M wrote:
Hi Shawn / Team ,
Need a suggestion on using the cloudsolrclient.
In our application, we have few cores which will be indexing every few minutes 
(starting from 15 mins intervall and searching will also be done by the users 
at the same time. Is it recommended to maintain a single cloudsolrclient 
throughout the application, something like a singleton? Im afraid if in a multi 
threaded env one thread shouldn’t hold the processing until the other 
completes. Kindly advise.

All SolrClient implementations, including CloudSolrClient and HttpSolrClient, are completely threadsafe. You can use them in many threads without causing any problems. If usage will be VERY heavy, you might need to fiddle with the object a little bit when you create it to allow more threads. Recent versions of SolrJ have sane defaults, but some of the older ones only run two threads at once if you don't change it. Things won't break with defaults on one of those older versions, you just might have performance issues. If necessary, I can fire up my IDE and figure out some code for you, you'll need to tell me what SolrJ version you have.

The general recommendation is to create one client object at program startup and then use that object everywhere in the program. If I understand the Singleton paradigm correctly, something similar is what we recommend.

You can either access the client object via a public static variable or build a public static synchronized method in a class that returns the client object, creating it if it doesn't already exist. Using public variables in a class is generally frowned on by experienced Java developers, I would go with the static method.

Thanks,
Shawn

Reply via email to