accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [1/5] git commit: ACCUMULO-2128 added waitForZooKeeperClientThreads method
Date Tue, 07 Jan 2014 02:05:21 GMT
Updated Branches:
  refs/heads/1.6.0-SNAPSHOT ee3ccb82d -> 9c092cadd


ACCUMULO-2128 added waitForZooKeeperClientThreads method

Signed-off-by: Keith Turner <kturner@apache.org>


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 <jaredwinick@koverse.com>
Authored: Thu Jan 2 22:30:59 2014 -0700
Committer: Keith Turner <kturner@apache.org>
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<Thread> 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);
+          }
+        }
+      }
+    }
   }
 }


Mime
View raw message