From 3f5dfabe48af0201319abe02eed12bf011e93bfc Mon Sep 17 00:00:00 2001 From: 1e99 <1e99@1e99.eu> Date: Sun, 17 Nov 2024 19:57:57 +0100 Subject: [PATCH] remove weird wait/notify structure in server --- server/src/eu/e99/svc/server/Server.java | 33 ++++++++++-------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/server/src/eu/e99/svc/server/Server.java b/server/src/eu/e99/svc/server/Server.java index 5b83efd..4ec5f38 100644 --- a/server/src/eu/e99/svc/server/Server.java +++ b/server/src/eu/e99/svc/server/Server.java @@ -26,31 +26,24 @@ public class Server { public void start() { while (true) { + Socket client; + + try { + client = this.socket.accept(); + } catch (Exception e) { + System.out.printf("Failed to accept client:%n"); + e.printStackTrace(System.out); + continue; + } + Thread.ofVirtual().start(() -> { - try (Socket client = this.socket.accept()) { - synchronized (this.socket) { - this.socket.notify(); - } - + try (client) { this.handleConnection(client); - } catch (IOException e) { - synchronized (this.socket) { - this.socket.notify(); - } - - System.out.printf("Failed to handle client.%n"); + } catch (Exception e) { + System.out.printf("Failed to handle client:%n"); e.printStackTrace(System.out); } }); - - try { - synchronized (this.socket) { - this.socket.wait(); - } - } catch (InterruptedException e) { - System.out.printf("Failed to wait on server socket to accept client.%n"); - e.printStackTrace(System.out); - } } }