在JDK中,它实现为:
public static void sleep(long millis, int nanos)
throws InterruptedException {
if (millis < 0) {
throw new IllegalArgumentException("timeout value is negative");
}
if (nanos < 0 || nanos > 999999) {
throw new IllegalArgumentException(
"nanosecond timeout value out of range");
}
if (nanos >= 500000 || (nanos != 0 && millis == 0)) {
millis++;
}
sleep(millis);
}
Run Code Online (Sandbox Code Playgroud)
这意味着nanos论证根本没有做任何事情.
它背后的想法是,在具有更精确计时的硬件上,JVM可以为它提供更好的实现吗?