From 2759097ef6d42941e870a48ce73b992a7397c5d4 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Thu, 26 Aug 2021 11:30:42 +0200 Subject: [PATCH] Cleaned up server run logic. --- .../nl/andrewl/concord_server/ConcordServer.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/nl/andrewl/concord_server/ConcordServer.java b/server/src/main/java/nl/andrewl/concord_server/ConcordServer.java index 5af63e6..e2e595d 100644 --- a/server/src/main/java/nl/andrewl/concord_server/ConcordServer.java +++ b/server/src/main/java/nl/andrewl/concord_server/ConcordServer.java @@ -184,7 +184,7 @@ public class ConcordServer implements Runnable { @Override public void run() { this.running = true; - this.scheduledExecutorService.scheduleAtFixedRate(this::publishMetaDataToDiscoveryServers, 1, 1, TimeUnit.MINUTES); + this.scheduledExecutorService.scheduleAtFixedRate(this::publishMetaDataToDiscoveryServers, 0, 1, TimeUnit.MINUTES); ServerSocket serverSocket; try { serverSocket = new ServerSocket(this.config.getPort()); @@ -195,12 +195,17 @@ public class ConcordServer implements Runnable { } System.out.println(startupMessage); while (this.running) { - Socket socket = serverSocket.accept(); - ClientThread clientThread = new ClientThread(socket, this); - clientThread.start(); + try { + Socket socket = serverSocket.accept(); + ClientThread clientThread = new ClientThread(socket, this); + clientThread.start(); + } catch (IOException e) { + e.printStackTrace(); + } } + serverSocket.close(); } catch (IOException e) { - e.printStackTrace(); + System.err.println("Could not open server socket: " + e.getMessage()); } this.scheduledExecutorService.shutdown(); }