]> source.dussan.org Git - sonarqube.git/commitdiff
Improve handling of some thread interruptions
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 21 Sep 2016 10:11:29 +0000 (12:11 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 21 Sep 2016 13:09:56 +0000 (15:09 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java
server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
server/sonar-process/src/main/java/org/sonar/process/StopWatcher.java
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java

index ffbfcb06dfb409b778456e9c96a0dc665a9aa2d8..6020f255e3615ffca0f3e84cb02c48b7bc3b21f2 100644 (file)
@@ -68,7 +68,8 @@ class StreamGobbler extends Thread {
       try {
         gobbler.join();
       } catch (InterruptedException ignored) {
-        // consider as finished
+        // consider as finished, restore the interrupted flag
+        Thread.currentThread().interrupt();
       }
     }
   }
index 2ca262205ce7aa29860bbab4cb033e4926820c3c..af3dd6302917dfd8efda2dfd5a655e3cad2746ee 100644 (file)
@@ -135,7 +135,7 @@ public class ProcessEntryPoint implements Stoppable {
       stopperThread.join();
       lifecycle.tryToMoveTo(Lifecycle.State.STOPPED);
     } catch (InterruptedException e) {
-      // nothing to do, the process is going to be exited
+      Thread.currentThread().interrupt();
     }
     exit.exit(0);
   }
index 3248e5195589f17aadb6094794bbaa1c9fb8c6d7..42cb2e9c3b2bc0d2605d5bca629f29346f4b8b3b 100644 (file)
@@ -56,6 +56,8 @@ public class StopWatcher extends Thread {
             Thread.sleep(delayMs);
           } catch (InterruptedException ignored) {
             watching = false;
+            // restore interrupted flag
+            Thread.currentThread().interrupt();
           }
         }
       }
index ee6afaf3487f69938642d6a219da1449f6484b35..d8bf14841fc60a579c83ce5e53313a4656ec54e2 100644 (file)
@@ -66,12 +66,13 @@ public class SearchServer implements Monitored {
 
   @Override
   public void awaitStop() {
-    while (node != null && !node.isClosed()) {
-      try {
+    try {
+      while (node != null && !node.isClosed()) {
         Thread.sleep(200L);
-      } catch (InterruptedException e) {
-        // Ignore
       }
+    } catch (InterruptedException e) {
+      // Restore the interrupted status
+      Thread.currentThread().interrupt();
     }
   }
 
index 2c68874a02912b6bb2183a1d66c3266fd512256c..e27f7124b81d02c7e7239fbc40834869c4448985 100644 (file)
@@ -147,7 +147,8 @@ public class CommandExecutor {
       try {
         thread.join();
       } catch (InterruptedException e) {
-        LOG.error("InterruptedException while waiting finish of " + thread.toString(), e);
+        // considered as finished, restore the interrupted flag
+        Thread.currentThread().interrupt();
       }
     }
   }