Here you can find the source of sleepNanos(long nanoDuration)
public static void sleepNanos(long nanoDuration)
//package com.java2s; //License from project: LGPL import java.util.concurrent.TimeUnit; public class Main { private static final long SLEEP_PRECISION = TimeUnit.MILLISECONDS.toNanos(4); private static final long SPIN_YIELD_PRECISION = TimeUnit.MILLISECONDS.toNanos(2); public static void sleepNanos(long nanoDuration) { final long end = System.nanoTime() + nanoDuration; long timeLeft = nanoDuration; do {//ww w .java2 s . c om try { if (timeLeft > SLEEP_PRECISION) { Thread.sleep(1); } else if (timeLeft > SPIN_YIELD_PRECISION) { Thread.sleep(0); } } catch (Exception e) { } timeLeft = end - System.nanoTime(); } while (timeLeft > 0); } }