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() {
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);
}
}
}