Use sleep on non-x86 architectures to avoid high cpu usage

This commit is contained in:
Andrea Cavalli 2021-04-03 02:35:31 +02:00
parent d666363b41
commit 4611461b3e

View File

@ -50,11 +50,17 @@ public class ResponseReceiver extends Thread implements AutoCloseable {
public void run() {
int[] sortIndex;
try {
while(!closeRequested || !registeredClients.isEmpty()) {
boolean useSpinWait = "amd64".equalsIgnoreCase(System.getProperty("os.arch"));
while (!closeRequested || !registeredClients.isEmpty()) {
int resultsCount = NativeClientAccess.receive(clientIds, eventIds, events, 2.0 /*seconds*/);
if (resultsCount <= 0) {
Thread.onSpinWait();
if (useSpinWait) {
Thread.onSpinWait();
} else {
//noinspection BusyWait
Thread.sleep(20);
}
continue;
}
@ -150,6 +156,8 @@ public class ResponseReceiver extends Thread implements AutoCloseable {
this.registeredClients.addAll(closedClients);
}
}
} catch (InterruptedException ex) {
throw new IllegalStateException(ex);
} finally {
this.closeWait.countDown();
}