Do spurious wakeups affect calls to Th开发者_开发技巧read.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?
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.
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
精彩评论