remove weird wait/notify structure in server

This commit is contained in:
1e99 2024-11-17 19:57:57 +01:00
parent 680c2fb8d3
commit 3f5dfabe48

View file

@ -26,31 +26,24 @@ public class Server {
public void start() { public void start() {
while (true) { 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(() -> { Thread.ofVirtual().start(() -> {
try (Socket client = this.socket.accept()) { try (client) {
synchronized (this.socket) {
this.socket.notify();
}
this.handleConnection(client); this.handleConnection(client);
} catch (IOException e) { } catch (Exception e) {
synchronized (this.socket) { System.out.printf("Failed to handle client:%n");
this.socket.notify();
}
System.out.printf("Failed to handle client.%n");
e.printStackTrace(System.out); 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);
}
} }
} }