The method Object#wait(long, long)
in java.lang.Object
states in it's documentation that
This method is similar to the
wait
method of one argument, but it allows finer control over the amount of time to wait for a notification before giving up. The amount of real time, measured in nanoseconds, is given by:1000000*timeout+nanos
This in itself makes sense, but the implementation does not reflect the documentation:
public final void wait(long timeout, int nanos) throws InterruptedException
{
// ... Some range checks
if (nanos >= 500000 || (nanos != 0 && timeout == 0))
{
timeout++;
}
wait(timeout);
}
As you can see, instead of actually using the nanos
parameter, it simply rounds it to milliseconds and adds it to the timeout
parameter, which it then uses to call the less precise wait(long)
method.
Why is the implementation of wait(long, long)
so different from it's documentation? Is it an intrinsic method that is treated specially by the JVM?