Java Thread.sleep() on Windows 10 stops in S3 sleep status -
there's desktop application uses thread.sleep() achieve long (minutes or hours) delays. same application has been working fine windows xp through (at least) windows 7. application calculates how far in future needs something, hits thread.sleep(mstowait). has been working fine, if system happens go s3 sleep state during wait.
as of windows 10, though, code after thread.sleep() not execute "on time" if machine has been in s3. appears machine begins executing code @ "mstowait" plus time machine has been in s3 (not 100% sure of right now, likely).
earlier versions of windows did not exhibit behavior; code after thread.sleep() waited right amount of time, irrespective of sleep status.
testing has been on current jvm 1.7.
is windows 10 bug? jvm bug? there work-around?
additional data:
a test program , procedure developed. procedure run program, cause machine sleep minute, wake machine , wait program finish.
if program run on windows 10 (reporting 8) jvm version: 25.40-b25, fails:
c:\users\tester\downloads>sleeptester.exe wed apr 01 10:47:35 pdt 2015 using default number of minutes: 5 wed apr 01 10:47:35 pdt 2015 can use "sleeptester -minutes 10" have sleep 10 minutes, example. wed apr 01 10:47:35 pdt 2015 jvm version: 25.40-b25 windows version: windows 8 wed apr 01 10:47:35 pdt 2015 program wait 5 minutes. expect wrap-up @ wed apr 01 10:52:35 pdt 2015 wed apr 01 10:53:38 pdt 2015 system has come through thread.sleep(300000). wed apr 01 10:53:38 pdt 2015 should low number: 63589 wed apr 01 10:53:38 pdt 2015 appears operating incorrectly...the expected sleep time has not been achieved. wed apr 01 10:53:38 pdt 2015 program ending.
if process run on windows 7, not fail.
wed apr 01 17:12:18 edt 2015 java runtime version: 1.8.0_31-b13 jvm version: 25.31-b07 windows version: windows 7 wed apr 01 17:12:18 edt 2015 program wait 6 minutes. expect wrap-up @ wed apr 01 17:18:18 edt 2015 wed apr 01 17:18:18 edt 2015 system has come through thread.sleep(360000). wed apr 01 17:18:18 edt 2015 should low number: 0 wed apr 01 17:18:18 edt 2015 program ending.
this test program:
import java.util.date; public class sleeptester { private static int mminutes; private static int mdefault = 5; public static void main(string[] args) throws exception { (int iarg = 0; iarg < args.length; ++iarg) { if (args[iarg].equals("-minutes") && (iarg + 1) < args.length) { mminutes = integer.parseint(args[++iarg]); } } if (mminutes == 0) { mminutes = mdefault; system.out.println(new date() + " using default number of minutes: " + mdefault); system.out.println(new date() + " can use \"sleeptester -minutes 10\" have sleep 10 minutes, example."); } system.out.println(new date() + " java runtime version: " + system.getproperty("java.runtime.version") + " jvm version: " + system.getproperty("java.vm.version") + " windows version: " + system.getproperty("os.name")); long msdelay = mminutes * 60 * 1000; long wakepoint = new date().gettime() + msdelay; system.out.println(new date() + " program wait " + mminutes + " minutes. expect wrap-up @ " + new date(wakepoint)); thread.sleep(msdelay); // if machine goes s3 during interval, should not matter, long it's awake when fires. system.out.println(new date() + " system has come through thread.sleep(" + msdelay + "). "); long msaccuracy = math.abs(new date().gettime() - wakepoint); system.out.println(new date() + " should low number: " + msaccuracy); if (msaccuracy > 1000) system.out.println(new date() + " appears operating incorrectly...the expected sleep time has not been achieved."); system.out.println(new date() + " program ending."); } }
i realize try various other methods sleep, thought since went through , documented this, i'd post here before trying other things.
additional information: failure seems appear in windows 8 (but not 7 or prior).
it's bug in windows 10.. os vital things done in metro start menu fail wake suspended state in timely fashion(depending of have firewalled or disabled, unsurprisingly enough). have suggested checking state of thread/process processhacker or sysinternals tools , try come solution. check windows event logs , such.
or silly replace sleep semaphore , sleep gets executed in command line.
the docs pretty sure imho should wake in timely fashion, shouldn't rely on output timer on datalines, playing music or such, taking 100x time little different.
Comments
Post a Comment