On 8/22/23 11:06, Tim Funk wrote:
I've tried to switch from the 8.X to 9.3 solrj client library. At the same
time - I switched to Http2SolrClient since the other was marked deprecated.
We use the client in the pattern ...

try (SolrClient client =  createSolrClient()) {
   response = client.query(solrQuery);
   // do stuff with response
}

Which should  auto close the client to clean things up. But we've noticed
on tomcat shutdown this error in the logs ...

That kind of try-with-resources approach should take care of the problem, because it would run the close() method on the SolrClient object.

The classes in the error are Jetty classes. This probably means that the problem is in Jetty, but I couldn't guarantee that.

You do not need multiple client objects just because you have multiple cores. You only need one Http2SolrClient object per hostname:port combination used to access Solr, and you should only need to create them when the application starts and close them when the application ends.

One thing I found about Http2SolrClient compared to HttpSolrClient: The latter creates the inner http client threads as Daemon threads, so they are automatically cleaned up by Java. The former doesn't. Here's some code to change the Http2SolrClient creation so that it creates the internal jetty http client threads as Daemon threads:

//-------------------------

final AtomicInteger scThreadCounter = new AtomicInteger();

// <snip>

final ExecutorService executorService = Executors.newFixedThreadPool(256, runnable -> { final Thread thread = Executors.defaultThreadFactory().newThread(runnable);
  thread.setDaemon(true); // Mark the thread as a daemon
  thread.setName("h2sc-" + scThreadCounter.incrementAndGet());
  return thread;
});

final Http2SolrClient.Builder clientBuilder = new Http2SolrClient.Builder(
  "http://localhost:8983/solr";).withExecutor(executorService);
final Http2SolrClient client = clientBuilder.build();

//-------------------------

One final note: You can still use HttpSolrClient. It will be removed from 10.0, but will still be there for all 9.x releases.

Thanks,
Shawn

Reply via email to