On 2/4/2022 6:49 PM, Steven White wrote:
This simple code, is causing me memory and thread loak (threads remain in
"sleeping" mode):
for (int j = 0; j < 10000; j++)
{
SolrClient solrClient = new
HttpSolrClient.Builder("foo-bar").build();
}
Any idea why? Is there an unbuild(), release() or something I have to call?
Why are you creating more than one client object?
As Walter said, when using HttpSolrClient, you need exactly one client
object across the entire application for each Solr instance. That
client object is completely thread-safe, and can access any
core/collection on the instance. There is no need to create a new
client object once you have used the previous one ... it should be good
for the life of the program.
If you were using CloudSolrClient, you would need one client object per
SolrCloud cluster. That client would be able to talk to any collection
in the cluster, and it is also aware of cluster changes in realtime --
servers being added/removed, servers going down or coming back up,
collections being added, removed, or modified, etc. Just like
HttpSolrClient, it is thread-safe.
As Mike said, SolrClient does have a close() method. If a client that
has been closed is keeping objects or threads around, we would almost
certainly consider that to be a bug.
Thanks,
Shawn