From d8b3452432b8ee9dd71c92f9e8f6eea43b894bca Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 20 Sep 2012 17:44:41 +0000 Subject: [PATCH] SOLR-3733: More improvements: don't hang on the died threads until forever... git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/solr3733@1388133 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/solr/common/cloud/SolrZooKeeper.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java index a926afc3131..e1c1f3952f8 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java @@ -21,8 +21,8 @@ import java.io.IOException; import java.lang.reflect.Field; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; import org.apache.zookeeper.ClientCnxn; import org.apache.zookeeper.Watcher; @@ -30,7 +30,7 @@ import org.apache.zookeeper.ZooKeeper; // we use this class to expose nasty stuff for tests public class SolrZooKeeper extends ZooKeeper { - List spawnedThreads = new CopyOnWriteArrayList(); + Set spawnedThreads = new CopyOnWriteArraySet(); // for test debug //static Map clients = new ConcurrentHashMap(); @@ -61,7 +61,7 @@ public class SolrZooKeeper extends ZooKeeper { * @param ms the number of milliseconds to pause. */ public void pauseCnxn(final long ms) { - Thread t = new Thread() { + final Thread t = new Thread() { public void run() { try { synchronized (cnxn) { @@ -72,11 +72,15 @@ public class SolrZooKeeper extends ZooKeeper { } Thread.sleep(ms); } - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + // ignore + } finally { + spawnedThreads.remove(this); + } } }; - t.start(); spawnedThreads.add(t); + t.start(); } @Override