Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. public static void sleepNanos (long nanoDuration) throws InterruptedException {
  2. final long end = System.nanoTime() + nanoDuration;
  3. long timeLeft = nanoDuration;
  4. do {
  5. if (timeLeft > SLEEP_PRECISION)
  6. Thread.sleep (1);
  7. else
  8. if (timeLeft > SPIN_YIELD_PRECISION)
  9. Thread.yield();
  10.  
  11. timeLeft = end - System.nanoTime();
  12. } while (timeLeft > 0);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement