Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do spurious wakeups affect Thread.sleep?

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?

like image 800
jsight Avatar asked Mar 05 '10 17:03

jsight


2 Answers

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.

like image 188
Jonathan Feinberg Avatar answered Sep 19 '22 15:09

Jonathan Feinberg


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

like image 28
Andrey Avatar answered Sep 21 '22 15:09

Andrey