Thread.sleep(1000)何时睡眠少于1000毫秒? [英] When does Thread.sleep(1000) sleeps less than 1000 milliseconds?
问题描述
在这篇有关程序员相信时间的谬论,其中之一是
In this interesting article about falsehoods programmers believe about time, one of them is
Thread.sleep(1000)睡眠> = 1000毫秒.
Thread.sleep(1000) sleeps for >= 1000 milliseconds.
什么时候不正确?
推荐答案
根据 timeGetDevCaps 函数来确定支持的最小计时器分辨率和
According to this (Implementation of the sleep by windows operating system, which is what Thread.sleep will call underneath): If dwMilliseconds is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on. To increase the accuracy of the sleep interval, call the timeGetDevCaps function to determine the supported minimum timer resolution and the timeBeginPeriod function to set the timer resolution to its minimum.
这篇关于Thread.sleep(1000)何时睡眠少于1000毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!