You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/07/21 01:22:58 UTC

[lucene-solr] branch reference_impl updated: @263 Don't leak sysstats thread.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl by this push:
     new a28b3c3  @263 Don't leak sysstats thread.
a28b3c3 is described below

commit a28b3c39d2662a2f0e3e808fcbab43ec29699f1b
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Mon Jul 20 20:22:37 2020 -0500

    @263 Don't leak sysstats thread.
---
 .../src/java/org/apache/solr/common/util/SysStats.java  | 17 ++++++++++++++---
 .../src/java/org/apache/solr/SolrTestCase.java          |  9 +++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/common/util/SysStats.java b/solr/solrj/src/java/org/apache/solr/common/util/SysStats.java
index fb9948b..1f613b0 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/SysStats.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/SysStats.java
@@ -17,7 +17,7 @@ public class SysStats extends Thread {
     static final int PROC_COUNT = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
 
     private long refreshInterval;
-    private boolean stopped;
+    private  volatile boolean stopped;
 
     private Map<Long, ThreadTime> threadTimeMap = new HashMap<Long, ThreadTime>(512);
     private ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
@@ -39,6 +39,13 @@ public class SysStats extends Thread {
         start();
     }
 
+    public static synchronized void reStartSysStats() {
+        if (sysStats != null) {
+            sysStats.stopMonitor();
+        }
+        sysStats = new SysStats(10000);
+    }
+
     public void doStop() {
         this.stopped = true;
     }
@@ -70,9 +77,12 @@ public class SysStats extends Thread {
 
             try {
                 Thread.sleep(refreshInterval);
+                if (stopped) {
+                    return;
+                }
             } catch (InterruptedException e) {
-                ParWork.propegateInterrupt(e);
-                throw new RuntimeException(e);
+                ParWork.propegateInterrupt(e, true);
+                return;
             }
 
             for (ThreadTime threadTime : values) {
@@ -107,6 +117,7 @@ public class SysStats extends Thread {
 
     public void stopMonitor() {
         this.stopped = true;
+        this.interrupt();
     }
 
     public double getTotalUsage() {
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
index 7db66a7..ec66f4d 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
@@ -39,6 +39,7 @@ import org.apache.solr.common.ParWorkExecutor;
 import org.apache.solr.common.TimeTracker;
 import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.ObjectReleaseTracker;
+import org.apache.solr.common.util.SysStats;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.servlet.SolrDispatchFilter;
 import org.apache.solr.util.ExternalPaths;
@@ -157,6 +158,12 @@ public class SolrTestCase extends LuceneTestCase {
   public static void setDefaultConfigDirSysPropIfNotSet() throws Exception {
     log.info("*******************************************************************");
     log.info("@BeforeClass ------------------------------------------------------");
+
+
+    if (!SysStats.getSysStats().isAlive()) {
+      SysStats.reStartSysStats();
+    }
+
     // random is expensive, you are supposed to cache it
     random = LuceneTestCase.random();
 
@@ -373,6 +380,8 @@ public class SolrTestCase extends LuceneTestCase {
       ExecutorUtil.shutdownAndAwaitTermination(CoreContainer.solrCoreLoadExecutor);
       CoreContainer.solrCoreLoadExecutor = null;
 
+      SysStats.getSysStats().stopMonitor();
+
       if (!failed) {
         // if the tests passed, make sure everything was closed / released
         String orr = ObjectReleaseTracker.checkEmpty();