@@ -86,6 +86,7 @@ public abstract class LBSolrClient extends SolrClient {
8686 private volatile EndpointWrapper [] aliveServerList = new EndpointWrapper [0 ];
8787
8888 private volatile ScheduledExecutorService aliveCheckExecutor ;
89+ private volatile boolean isClosed = false ;
8990
9091 protected long aliveCheckIntervalMillis =
9192 TimeUnit .MILLISECONDS .convert (60 , TimeUnit .SECONDS ); // 1 minute between checks
@@ -574,11 +575,16 @@ private void startAliveCheckExecutor() {
574575 // if it's not null.
575576 if (aliveCheckExecutor == null ) {
576577 synchronized (this ) {
578+ if (isClosed ) {
579+ // must check inside sync block
580+ return ;
581+ }
577582 if (aliveCheckExecutor == null ) {
578583 log .debug ("Starting aliveCheckExecutor for {}" , this );
579584 aliveCheckExecutor =
580585 Executors .newSingleThreadScheduledExecutor (
581586 new SolrNamedThreadFactory ("aliveCheckExecutor" ));
587+ ObjectReleaseTracker .track (aliveCheckExecutor );
582588 aliveCheckExecutor .scheduleAtFixedRate (
583589 getAliveCheckRunner (new WeakReference <>(this )),
584590 this .aliveCheckIntervalMillis ,
@@ -825,8 +831,10 @@ protected EndpointWrapper pickServer(EndpointWrapper[] aliveServerList, SolrRequ
825831 @ Override
826832 public void close () {
827833 synchronized (this ) {
834+ isClosed = true ;
828835 if (aliveCheckExecutor != null ) {
829836 ExecutorUtil .shutdownNowAndAwaitTermination (aliveCheckExecutor );
837+ ObjectReleaseTracker .release (aliveCheckExecutor );
830838 }
831839 }
832840 ObjectReleaseTracker .release (this );
0 commit comments