Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8298B18561 for ; Fri, 15 Jan 2016 03:42:47 +0000 (UTC) Received: (qmail 20999 invoked by uid 500); 15 Jan 2016 03:42:47 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 20937 invoked by uid 500); 15 Jan 2016 03:42:47 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 20846 invoked by uid 99); 15 Jan 2016 03:42:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jan 2016 03:42:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E1B97E3872; Fri, 15 Jan 2016 03:42:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Fri, 15 Jan 2016 03:42:52 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [7/7] 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 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-208 Commit: 36a72d9c509a796d9e2bc112fab9356148a13f76 Parents: f73dc08 Author: randgalt Authored: Thu Jan 14 22:42:24 2016 -0500 Committer: randgalt 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() { @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"); } }