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
This commit is contained in:
Uwe Schindler 2012-09-20 17:44:41 +00:00
parent 024e22c873
commit d8b3452432
1 changed files with 10 additions and 6 deletions

View File

@ -21,8 +21,8 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.channels.SelectableChannel; import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.util.List; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.zookeeper.ClientCnxn; import org.apache.zookeeper.ClientCnxn;
import org.apache.zookeeper.Watcher; import org.apache.zookeeper.Watcher;
@ -30,7 +30,7 @@ import org.apache.zookeeper.ZooKeeper;
// we use this class to expose nasty stuff for tests // we use this class to expose nasty stuff for tests
public class SolrZooKeeper extends ZooKeeper { public class SolrZooKeeper extends ZooKeeper {
List<Thread> spawnedThreads = new CopyOnWriteArrayList<Thread>(); Set<Thread> spawnedThreads = new CopyOnWriteArraySet<Thread>();
// for test debug // for test debug
//static Map<SolrZooKeeper,Exception> clients = new ConcurrentHashMap<SolrZooKeeper,Exception>(); //static Map<SolrZooKeeper,Exception> clients = new ConcurrentHashMap<SolrZooKeeper,Exception>();
@ -61,7 +61,7 @@ public class SolrZooKeeper extends ZooKeeper {
* @param ms the number of milliseconds to pause. * @param ms the number of milliseconds to pause.
*/ */
public void pauseCnxn(final long ms) { public void pauseCnxn(final long ms) {
Thread t = new Thread() { final Thread t = new Thread() {
public void run() { public void run() {
try { try {
synchronized (cnxn) { synchronized (cnxn) {
@ -72,11 +72,15 @@ public class SolrZooKeeper extends ZooKeeper {
} }
Thread.sleep(ms); Thread.sleep(ms);
} }
} catch (InterruptedException e) {} } catch (InterruptedException e) {
// ignore
} finally {
spawnedThreads.remove(this);
}
} }
}; };
t.start();
spawnedThreads.add(t); spawnedThreads.add(t);
t.start();
} }
@Override @Override