From c37662f7f8ff8037165654d3fafbd967779fffb1 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 9 Nov 2014 23:03:28 +0100 Subject: [PATCH] Minor optimization in TimedThread class. --- src/de/teamteamteam/spacescooter/thread/TimedThread.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/thread/TimedThread.java b/src/de/teamteamteam/spacescooter/thread/TimedThread.java index 56f9a1a..c9b5a13 100644 --- a/src/de/teamteamteam/spacescooter/thread/TimedThread.java +++ b/src/de/teamteamteam/spacescooter/thread/TimedThread.java @@ -45,10 +45,12 @@ public abstract class TimedThread extends Thread { //wait manually for the rest of the interval long sleepUntil = workStart + this.workInterval; - while ((sleepUntil- System.nanoTime()) > 0) { - if((sleepUntil- System.nanoTime()) > 5000) { + long currentTime = System.nanoTime(); + while ((sleepUntil - currentTime) > 10) { + if((sleepUntil - currentTime) > 10000) { Thread.yield(); //Give other threads a chance. } + currentTime = System.nanoTime(); } } }