> but I don't think System.currentTimeMillis is accurate though. Same
> number shows for up to 4 consecutive loops

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
>> but I don't think System.currentTimeMillis is accurate though. Same
>> number shows for up to 4 consecutive loops
[quoted text clipped - 3 lines]
> multiple times if you call it again within 1 ms. What else would you
> expect?
System.nanoTime should be better (from 1.5). It theoretically isn't
affected by changing the system time either.
> In the code I posted, individual passes through the loop will jitter
> if System.currentTimeMillis() not as accurate as you want, and this is
> unavoidable. However the long term error is zero because the short
> term errors on each pass do not accumulate, and variations in the
> "your stuff" part of the loop are compensated for.
On average when you call System.currentTimeMillis, Thread.sleep or
anything else, you will be halfway between increments. So if you wait
until it next increments, that will on average be half the period of an
increment. Therefore, you shouldn't expect sleeps to average a round time.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/