I use the following loop (cut some stuff out) as the main loop for a game, but I can't get it to throttle down to a speed I want it to, it keeps running about twice as fast as I intend.

```
private void myLoop() throws InterruptedException {

    long timer = TimeUtils.getMillis();

    int achievedLoops = 0;

    long currTime = 0l;
    long loopTime = 0l;
    long lastTime = TimeUtils.getNano();

    while(!isRequestedToStop) {
        currTime = TimeUtils.getNano();
        loopTime = currTime - lastTime;
        lastTime = currTime;

        if(TimeUtils.getDeltaMillis(timer) > 1000) {
            timer += 1000;
            logger.debug(achievedLoops + " Loops");
            achievedLoops = 0;
        }

        achievedLoops++;

        if(loopTime < TIME_PER_LOOP) {
            Thread.sleep( (TIME_PER_LOOP - loopTime) / 1000000l);
        }
    }
}

```

Alternative implementation of the sleeping, gets slightly better results (loop runs only 1.9 times too often):

```
while(loopTime < TIME_PER_LOOP) {
    Thread.sleep(1l);
    loopTime += 1000000l;
}

```

Another alternative:

```
while(loopTime < TIME_PER_LOOP) {
    Thread.sleep(1l);
    loopTime = TimeUtils.getNano() - lastTime;
}

```

**Why does that happen?  

Are there any other ways to throttle a thread down?**

I basically could run it uncontrolled as the logic is tied to timed steps, but I would like to reduce the total runs of the loop as otherwise there's a marginal chance of it doing damage to a CPU..