You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by jd...@apache.org on 2024/03/21 13:54:26 UTC
(solr) branch branch_9x updated: HttpJdkSolrClient: Close the underlying http client, if it is supported (java 21+) (#2362)
This is an automated email from the ASF dual-hosted git repository.
jdyer pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new d705bef9f94 HttpJdkSolrClient: Close the underlying http client, if it is supported (java 21+) (#2362)
d705bef9f94 is described below
commit d705bef9f94754270b09c5b86dc48667f04fc559
Author: James Dyer <jd...@apache.org>
AuthorDate: Thu Mar 21 08:52:41 2024 -0500
HttpJdkSolrClient: Close the underlying http client, if it is supported (java 21+) (#2362)
* Close the underlying http client, if it is supported (java 21+)
* tidy
---
.../apache/solr/client/solrj/impl/HttpJdkSolrClient.java | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java
index 63d1d3ca207..35e56ae2a55 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java
@@ -410,14 +410,21 @@ public class HttpJdkSolrClient extends HttpSolrClientBase {
@Override
public void close() throws IOException {
+ // If used with Java 21+
+ if (httpClient instanceof AutoCloseable) {
+ try {
+ ((AutoCloseable) httpClient).close();
+ } catch (Exception e) {
+ log.warn("Could not close the http client.", e);
+ }
+ }
+ httpClient = null;
+
if (shutdownExecutor) {
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
executor = null;
- // TODO: Java 21 adds close/autoclosable to HttpClient. We should use it.
- httpClient = null;
-
assert ObjectReleaseTracker.release(this);
}