Updated Branches:
  refs/heads/master b8bd259d0 -> 4fbba38ae

ACCUMULO-2128 added waitForZooKeeperClientThreads method

Signed-off-by: Keith Turner <ktur...@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/master
Commit: c94a73f478c91a24e35583d41bb39102461c54fa
Parents: 715825b
Author: Jared Winick <jaredwin...@koverse.com>
Authored: Thu Jan 2 22:30:59 2014 -0700
Committer: Keith Turner <ktur...@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);
+          }
+        }
+      }
+    }
   }
 }

Reply via email to