curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [8/9] curator git commit: Don't let thread interrupt status get reset. The only proper reason for these loops to exit if the instance is closed
Date Mon, 18 Jan 2016 00:29:59 GMT
Don't let thread interrupt status get reset. The only proper reason for these loops to exit
if the instance is closed


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/36a72d9c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/36a72d9c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/36a72d9c

Branch: refs/heads/CURATOR-3.0
Commit: 36a72d9c509a796d9e2bc112fab9356148a13f76
Parents: f73dc08
Author: randgalt <randgalt@apache.org>
Authored: Thu Jan 14 22:42:24 2016 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Thu Jan 14 22:42:24 2016 -0500

----------------------------------------------------------------------
 .../framework/imps/CuratorFrameworkImpl.java    | 37 ++++++++++++--------
 1 file changed, 22 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/36a72d9c/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index dddcfe4..442579d 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -22,6 +22,7 @@ package org.apache.curator.framework.imps;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import org.apache.curator.CuratorConnectionLossException;
 import org.apache.curator.CuratorZookeeperClient;
@@ -257,8 +258,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
 
             client.start();
 
-            executorService = Executors.newFixedThreadPool(2, threadFactory);  // 1 for listeners,
1 for background ops
-
+            executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
             executorService.submit(new Callable<Object>()
             {
                 @Override
@@ -794,24 +794,31 @@ public class CuratorFrameworkImpl implements CuratorFramework
 
     private void backgroundOperationsLoop()
     {
-        while ( !Thread.currentThread().isInterrupted() )
+        try
         {
-            OperationAndData<?> operationAndData;
-            try
+            while ( state.get() == CuratorFrameworkState.STARTED )
             {
-                operationAndData = backgroundOperations.take();
-                if ( debugListener != null )
+                OperationAndData<?> operationAndData;
+                try
                 {
-                    debugListener.listen(operationAndData);
+                    operationAndData = backgroundOperations.take();
+                    if ( debugListener != null )
+                    {
+                        debugListener.listen(operationAndData);
+                    }
+                    performBackgroundOperation(operationAndData);
+                }
+                catch ( InterruptedException e )
+                {
+                    // swallow the interrupt as it's only possible from either a background
+                    // operation and, thus, doesn't apply to this loop or the instance
+                    // is being closed in which case the while test will get it
                 }
             }
-            catch ( InterruptedException e )
-            {
-                Thread.currentThread().interrupt();
-                break;
-            }
-
-            performBackgroundOperation(operationAndData);
+        }
+        finally
+        {
+            log.info("backgroundOperationsLoop exiting");
         }
     }
 


Mime
View raw message