From b132fac7b025e55cff4a29d4d709050cae0889b3 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 24 Oct 2014 23:45:31 +0200 Subject: [PATCH] Use Thread.yield() in order to make active waiting less painful. --- src/de/teamteamteam/spacescooter/threads/TimingThread.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/teamteamteam/spacescooter/threads/TimingThread.java b/src/de/teamteamteam/spacescooter/threads/TimingThread.java index 47adc66..93c7302 100644 --- a/src/de/teamteamteam/spacescooter/threads/TimingThread.java +++ b/src/de/teamteamteam/spacescooter/threads/TimingThread.java @@ -40,7 +40,11 @@ public abstract class TimingThread extends Thread { //wait manually for the rest of the interval long sleepUntil = workStart + this.workInterval; - while ((sleepUntil- System.nanoTime()) > 100); + while ((sleepUntil- System.nanoTime()) > 0) { + if((sleepUntil- System.nanoTime()) > 5000) { + Thread.yield(); //Give other threads a chance. + } + } } }