Giving Thread.sleep( ); a decimal value
Is this possible in any way? The values are always between 0 and 2, and it is looped over 2000 times (Yes it has to be that way) so accuracy does count. I would post the source but I feel it would not help in this situation. Thread.sleep() won't accept non-integer values, so if anyone knows some sort of workaround, please let me know.
Re: Giving Thread.sleep( ); a decimal value
Unfortunately, the sleeping mechanism of many operating systems does not have resolution below 1 ms (and many don't even have this). If you need precise timing, the only way I can think of is using some sort of "active" waiting, or resorting to JNI/C++.
Re: Giving Thread.sleep( ); a decimal value
Thanks for the reply, I tried using C++ but quickly realized this would be too difficult for each time I wanted to test it, so I ended up using a loop to pause the program.
Code :
time1=System.currentTimeMillis();
while (time2-time1 < sleeptime) {
time2=System.currentTimeMillis();
if (time2-time1 == sleeptime || time2-time1 > sleeptime) {break;}
}
It still is not perfectly accurate (and nothing will ever be), but it is as good as I need it to be.