-
Enhancement
-
Resolution: Fixed
-
P4
-
21
-
b21
Java API has the `Thread.sleep(millis, nanos)` method exposed to users. The documentation for that method clearly says the precision and accuracy are dependent on the underlying system behavior.
However, it always rounds up `nanos` to 1ms when doing the actual sleep. This means users cannot do the micro-second precision sleeps, even when the underlying platform allows it. Sub-millisecond sleeps are useful to build interesting primitives, like the rate limiters that run with >1000 RPS.
When faced with this, some users reach for more awkward APIs like `java.util.concurrent.locks.LockSupport.parkNanos`. The use of that API for sleeps is not in line with its intent, and it might have unpredictable impact on the `java.util.concurrent`-built primitives. Additionally, these "sleeps" are no longer visible to monitoring tools as "normal sleeps".
Therefore, it would be prudent to improve current `Thread.sleep(millis, nanos)` for sub-millisecond granularity. Fortunately, the underlying code is almost ready for this, at least on POSIX side.
However, it always rounds up `nanos` to 1ms when doing the actual sleep. This means users cannot do the micro-second precision sleeps, even when the underlying platform allows it. Sub-millisecond sleeps are useful to build interesting primitives, like the rate limiters that run with >1000 RPS.
When faced with this, some users reach for more awkward APIs like `java.util.concurrent.locks.LockSupport.parkNanos`. The use of that API for sleeps is not in line with its intent, and it might have unpredictable impact on the `java.util.concurrent`-built primitives. Additionally, these "sleeps" are no longer visible to monitoring tools as "normal sleeps".
Therefore, it would be prudent to improve current `Thread.sleep(millis, nanos)` for sub-millisecond granularity. Fortunately, the underlying code is almost ready for this, at least on POSIX side.
- csr for
-
JDK-8306463 Improve Thread.sleep(millis, nanos) for sub-millisecond granularity
- Closed
- relates to
-
JDK-8309361 Regression in SPECjbb2015 application latencies
- Open
-
JDK-8307782 Compensate for timed wait lags on Thread.sleep paths
- Closed