java - What's the purpose of sleep(long millis, int nanos)? -
in jdk, it's implemented as:
public static void sleep(long millis, int nanos) throws interruptedexception { if (millis < 0) { throw new illegalargumentexception("timeout value 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); }
which means nanos
argument doesn't @ all.
is idea behind on hardware more accurate timing, jvm can provide better implementation it?
a regular os doesn't have fine grained enough resolution sleep nanoseconds @ time. however, real time operating systems exist, scheduling event take place @ exact moment in time critical , latencies many operations low. abs system 1 example of rtos. sleeping nanoseconds more useful on such systems on normal oses os can't reliably sleep period less 15ms.
however, having 2 separate jdks no solution. hence on windows , linux jvm make best attempt sleep x nanoseconds.
Comments
Post a Comment