RFR: 8305092: Improve Thread.sleep(millis, nanos) for sub-millisecond granularity [v3]

Aleksey Shipilev shade at openjdk.org
Wed Apr 19 09:22:44 UTC 2023


On Wed, 19 Apr 2023 08:15:44 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Thread.java line 576:
>> 
>>> 574:         long millis = NANOSECONDS.toMillis(nanos);
>>> 575:         nanos -= MILLISECONDS.toNanos(millis);
>>> 576:         sleep(millis, (int)nanos);
>> 
>> This double conversion seems  a bit kludgy - why not just keep the vthread check and call `sleep0(nanos)`?
>
> Yes, I wondering that too as the method has the sleep time in nanos already so more readable to just call sleep0(nanos).

True. I was trying to merge some paths in `Thread.java` in the first revision of the patch, but after recent refactorings, we can just call into `sleep0(nanos)` and be done with it.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13225#discussion_r1171065587


More information about the core-libs-dev mailing list