Close the main selector

This commit is contained in:
TheMode 2021-08-04 05:19:11 +02:00
parent 8895e49a52
commit 0d91f9efc6

View File

@ -24,6 +24,7 @@ public class Server {
private volatile boolean stop;
private final Selector selector = Selector.open();
private final List<Worker> workers = new ArrayList<>(WORKER_COUNT);
private int index;
@ -39,7 +40,6 @@ public class Server {
}
public void start(SocketAddress address) throws IOException {
Selector selector = Selector.open();
this.serverSocket = ServerSocketChannel.open();
serverSocket.bind(address);
serverSocket.configureBlocking(false);
@ -65,6 +65,7 @@ public class Server {
public void stop() {
this.stop = true;
this.selector.wakeup();
this.workers.forEach(worker -> worker.selector.wakeup());
}