Minor optimization in TimedThread class.

This commit is contained in:
Jan Philipp Timme 2014-11-09 23:03:28 +01:00
parent d59fbafd8c
commit c37662f7f8
1 changed files with 4 additions and 2 deletions

View File

@ -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();
}
}
}