remove weird wait/notify structure in server
This commit is contained in:
parent
680c2fb8d3
commit
3f5dfabe48
1 changed files with 13 additions and 20 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue