sleep first in loop to avoid skipping sleep with continue

This commit is contained in:
Luca Conte 2024-11-30 14:13:15 +01:00
parent 7303f49d0d
commit ff9ffbd628
1 changed files with 6 additions and 6 deletions

View File

@ -24,6 +24,11 @@ public class AsyncSocket {
this.checkerThread = new Thread(() -> {
while (!this.shouldStop) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
if (!this.in.ready()) continue;
if (this.handler == null) continue;
@ -31,16 +36,11 @@ public class AsyncSocket {
String message = this.in.readLine();
if (message.length() <= 0) continue;
// TODO: remove \r\n
this.handler.receive(message);
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
this.checkerThread.start();