views:

112

answers:

2

Do spurious wakeups affect calls to Thread.sleep(x)? Obviously, the timer is not 100% precise (leading to minor inaccuracies in wakeup times), but is it affected by the spurious wakeup problem?

+6  A: 

You're asking whether Thread.sleep() is affected by the same spurious wakeup issue that is documented to affect Object.wait(long), right? The answer is that there is no documented spurious wakeup associated with Thread.sleep(). You're right that no hard guarantees are made about exactly how long you'll sleep when you request N milliseconds. Also, of course, Thread.sleep() terminates on thread interrupt.

Jonathan Feinberg
+2  A: 

real interval of sleep is always >= required interval. it is especially sensitive on small intervals.

now about "spurious wakeups". it was not mentioned about Thread.sleep

Andrey