@Override public void pause() throws InterruptedException { while (next > timeSystem.currentTimeInNanos()) { LockSupport.parkNanos(next - timeSystem.currentTimeInNanos()); if ( Thread.currentThread().isInterrupted() ) { throw new InterruptedException(); } } next = next + periodInNanos; }
long periodInNanos = unit.toNanos(period); return new Metronome() { private long next = timeSystem.currentTimeInNanos() + periodInNanos;
@Override public void pause() throws InterruptedException { while (next > timeSystem.currentTimeInNanos()) { LockSupport.parkNanos(next - timeSystem.currentTimeInNanos()); if ( Thread.currentThread().isInterrupted() ) { throw new InterruptedException(); } } next = next + periodInNanos; }
long periodInNanos = unit.toNanos(period); return new Metronome() { private long next = timeSystem.currentTimeInNanos() + periodInNanos;