Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4CEE410CD5 for ; Tue, 7 Jan 2014 02:05:22 +0000 (UTC) Received: (qmail 23748 invoked by uid 500); 7 Jan 2014 02:05:22 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 23726 invoked by uid 500); 7 Jan 2014 02:05:22 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 23718 invoked by uid 99); 7 Jan 2014 02:05:22 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jan 2014 02:05:22 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B5D79385D7; Tue, 7 Jan 2014 02:05:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kturner@apache.org To: commits@accumulo.apache.org Date: Tue, 07 Jan 2014 02:05:21 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/5] git commit: ACCUMULO-2128 added waitForZooKeeperClientThreads method Updated Branches: refs/heads/1.6.0-SNAPSHOT ee3ccb82d -> 9c092cadd ACCUMULO-2128 added waitForZooKeeperClientThreads method Signed-off-by: Keith Turner Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c94a73f4 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c94a73f4 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c94a73f4 Branch: refs/heads/1.6.0-SNAPSHOT Commit: c94a73f478c91a24e35583d41bb39102461c54fa Parents: 715825b Author: Jared Winick Authored: Thu Jan 2 22:30:59 2014 -0700 Committer: Keith Turner Committed: Mon Jan 6 20:17:58 2014 -0500 ---------------------------------------------------------------------- .../org/apache/accumulo/core/util/CleanUp.java | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/c94a73f4/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java ---------------------------------------------------------------------- diff --git a/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java b/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java index ba02f0b..5b2a4b9 100644 --- a/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java +++ b/src/core/src/main/java/org/apache/accumulo/core/util/CleanUp.java @@ -16,20 +16,48 @@ */ package org.apache.accumulo.core.util; +import java.util.Set; + import org.apache.accumulo.core.client.impl.ThriftTransportPool; import org.apache.accumulo.core.zookeeper.ZooSession; +import org.apache.log4j.Logger; /** * */ public class CleanUp { + + private static final Logger log = Logger.getLogger(CleanUp.class); + /** * kills all threads created by internal Accumulo singleton resources. After this method is called, no accumulo client will work in the current classloader. */ public static void shutdownNow() { ThriftTransportPool.getInstance().shutdown(); ZooSession.shutdown(); - // need to get code from jared w - // waitForZooKeeperClientThreads(); + waitForZooKeeperClientThreads(); + } + + /** + * As documented in https://issues.apache.org/jira/browse/ZOOKEEPER-1816, ZooKeeper.close() + * is a non-blocking call. This method will wait on the ZooKeeper internal threads to exit. + */ + private static void waitForZooKeeperClientThreads() { + Set threadSet = Thread.getAllStackTraces().keySet(); + for (Thread thread : threadSet) { + // find ZooKeeper threads that were created in the same ClassLoader as the current thread. + if (thread.getClass().getName().startsWith("org.apache.zookeeper.ClientCnxn") && + thread.getContextClassLoader().equals(Thread.currentThread().getContextClassLoader())) { + + // wait for the thread the die + while (thread.isAlive()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + log.error(e.getMessage(), e); + } + } + } + } } }