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

前端 未结 2 1816
一向
一向 2021-01-04 06:34

There\'s a desktop application that uses Thread.sleep() to achieve long (minutes or hours) delays. This same application has been working fine from Windows XP through (at l

相关标签:
2条回答
  • 2021-01-04 06:55

    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.

    0 讨论(0)
  • 2021-01-04 06:59

    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.

    0 讨论(0)
提交回复
热议问题