You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/03/06 15:48:19 UTC

svn commit: r1664639 - /sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java

Author: cziegeler
Date: Fri Mar  6 14:48:19 2015
New Revision: 1664639

URL: http://svn.apache.org/r1664639
Log:
SLING-4477 : JcrInstaller should not call Thread.interrupt()

Modified:
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1664639&r1=1664638&r2=1664639&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java (original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java Fri Mar  6 14:48:19 2015
@@ -214,7 +214,11 @@ public class JcrInstaller implements Eve
     /** Thread that can be cleanly stopped with a flag */
     static int bgThreadCounter;
     class StoppableThread extends Thread {
+
+        /** Used for synchronizing. */
+        final Object lock = new Object();
         boolean active = true;
+
         StoppableThread() {
             synchronized (JcrInstaller.class) {
                 setName("JcrInstaller." + (++bgThreadCounter));
@@ -390,16 +394,14 @@ public class JcrInstaller implements Eve
     private void stop() {
     	logger.info("Deactivating Apache Sling JCR Installer");
 
-    	final long timeout = 30000L;
-        backgroundThread.active = false;
-        logger.debug("Waiting for " + backgroundThread.getName() + " Thread to end...");
-        backgroundThread.interrupt();
-    	try {
-            backgroundThread.join(timeout);
-    	} catch(InterruptedException iex) {
-    	    // ignore this as we want to shutdown
+    	if ( backgroundThread != null ) {
+    	    synchronized ( backgroundThread.lock ) {
+    	        backgroundThread.active = false;
+    	        backgroundThread.lock.notify();
+    	    }
+            logger.debug("Waiting for " + backgroundThread.getName() + " Thread to end...");
+            backgroundThread = null;
     	}
-        backgroundThread = null;
 
         folderNameFilter = null;
         watchedFolders = null;
@@ -670,10 +672,12 @@ public class JcrInstaller implements Eve
             logger.warn("Exception in runOneCycle()", e);
         }
 
-        try {
-            Thread.sleep(RUN_LOOP_DELAY_MSEC);
-        } catch (final InterruptedException ignore) {
-            // ignore
+        synchronized ( backgroundThread.lock ) {
+            try {
+                backgroundThread.lock.wait(RUN_LOOP_DELAY_MSEC);
+            } catch (final InterruptedException ignore) {
+                Thread.currentThread().interrupt();
+            }
         }
         counters[RUN_LOOP_COUNTER]++;
     }