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

Thorsten Goetzke tg at freigmbh.de
Mon Aug 27 05:23:53 EDT 2018


> IMHO if your code breaks because Thread.sleep woke up too early or too 
> late, your code was incorrect to start with.  Same with wait(), which 
> can be subject to spurious wakeups apparently.

Well it's not productive code, the situation is: We want to  simulate 
code, (for testing purpose) that does't return for 123 (or whatever) 
millisecends or more (for example to simulate a query-timeout). It just 
a bit sad that the most simple, straightforward approach sleep(123) 
breaks on some machines because it doesn't actually sleeps as long as 
needed. It's easily fixable when you know what's going on, but you have 
to be aware.



More information about the Concurrency-interest mailing list