NioClientManager: use a daemon thread so GUI apps can quit fast if they want to without a slow/hung network thread keeping things hanging around. This may break compatibility with apps that expect to be able to start bitcoinj and then exit the main thread: if it causes too many problems this change may be reverted.

This commit is contained in:
Mike Hearn
2015-01-28 16:20:51 +01:00
parent f4cce4c3c0
commit ad4fb5103c

View File

@@ -17,10 +17,7 @@
package org.bitcoinj.net; package org.bitcoinj.net;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.util.concurrent.AbstractExecutionThreadService; import com.google.common.util.concurrent.*;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
@@ -29,7 +26,7 @@ import java.net.SocketAddress;
import java.nio.channels.*; import java.nio.channels.*;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
import java.util.*; import java.util.*;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.*;
/** /**
* A class which manages a set of client connections. Uses Java NIO to select network events and processes them in a * A class which manages a set of client connections. Uses Java NIO to select network events and processes them in a
@@ -185,4 +182,16 @@ public class NioClientManager extends AbstractExecutionThreadService implements
handler.closeConnection(); // Removes handler from connectedHandlers before returning handler.closeConnection(); // Removes handler from connectedHandlers before returning
} }
} }
@Override
protected Executor executor() {
return new Executor() {
@Override
public void execute(Runnable command) {
Thread thread = new Thread(command, "NioClientManager");
thread.setDaemon(true);
thread.start();
}
};
}
} }