Java Thread.sleep() on Windows 10 stops in S3 sleep status

牧云@^-^@ 提交于 2019-11-30 17:37:44

This is expected, valid behavior. The documentation is very explicit, stating:

these sleep times are not guaranteed to be precise, because they are limited by the facilities provided by the underlying OS.

and:

In any case, you cannot assume that invoking sleep will suspend the thread for precisely the time period specified.

it's probably a bug in windows 10.. even os vital things done in metro like the start menu sometimes fail to wake up from suspended state in a timely fashion(depending of what all you have firewalled or disabled, unsurprisingly enough). I would have suggested checking the state of the thread/process with processhacker or some sysinternals tools and try to come up with some solution. then check with windows event logs and such.

or just do something silly like replace the sleep with a semaphore and sleep that gets executed in the command line.

the docs are pretty sure imho that it should wake up in a timely fashion, just that you shouldn't rely on it as an output timer on some datalines, playing music or such, but taking 100x the time is a little different.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!