[concurrency-interest] Sleep time consistency compared to System.currentTimeMillis

Thorsten Goetzke tg at freigmbh.de
Mon Aug 27 04:30:27 EDT 2018

> On 08/24/2018 05:10 AM, Thorsten Goetzke via Concurrency-interest wrote:
>> Hello,
>> There are multiple Classes that let you wait or sleep for a specified
>> amount of time. My current understanding is:
>> Thread.sleep and Object.wait can wake up earlier than specified so code
>> that also uses System.currentTimeMillies can break because wakeups
>> happen to early.
> Yes, and the JDK API specs for these methods include disclaimers,
> including: "The specified amount of real time has elapsed, more or less."

I think in case of Thread.sleep the javadoc should be clarified so it 
explicitly contains the word "less".
It just says "subject to the precision and accuracy of system timers and 
schedulers" which can be missunderstood as "at least sleep time + the 
jvm does it's best to reduce additional sleep time but it obviosly cant 
magically make the undlerying system more precise".


More information about the Concurrency-interest mailing list