Search code examples
javasolrj

Is CloudSolrClient thread safe?


I am trying to use CloudSolrClient instance in a multithread environment. Is CloudSolrClient class thread-safe ? or should it be managed as database connection pool?

Any advise will be of great help.

Thanks


Solution

  • Yes, CloudSolrClient is thread safe and you can share a configured singleton between all your threads.

    There are just few precautions:

    CloudSolrClient isn't thread-safe if you're making requests to multiple collections, because defaultCollection is mutable. This can be a pain if you're trying to index into multiple collections from a single queue of documents.

    But you can have multiple CloudSolrClient instances, one configured for each collection.