RTC speeds up by calls to System.currentTimeMillis()
I observed a rather strange behaviour lately with JRE1.5 (newest version) and Win XP. Indeed it's 100% sure that calling currentTimeMillis (or sleep?) too frequent will speed up the system's real time clock under XP.
But let me explain...
I'm using the following to achieve constant timing in a game project (simplified):
publicvoid run(){
long timeBaseRepaint = System.currentTimeMillis();
while (true){
long t = System.currentTimeMillis();
if (t >= timeBaseRepaint + 33){
timeBaseRepaint += 33;
redraw();// does also repaint
}else{
try{
Thread.sleep(1);
}catch (InterruptedException ex){}
}
}
}
Well, I had more complex version measuring the time to sleep etc. However they either led to strange timing behaviour or they messed up the music played in another thread.
Anyway, after I used this simplified version yesterday, I could observe that the the redraw/repaint was done more often in a second then it should be.. I wondered why but couldn't really find out.
Today I tried the project on another XP system and it ran at about the double speed it should. After trying my game for some time, I suddenly noticed my system time was off by about 20 minutes.
Then I opened the analog windows watch and noticed that it speeded up to roughly the doubled speed as long as my game was running. As soon as I stopped the game, the clock continued at normal pace. As soon as I started my game again, it would run at high speed again.
I'm puzzled - no way should a Java application be able to mess with the system's real time clock. But my application does and just by calling some normal timing functions. This happens on at least two completely differenty installed windows XP systems - though the factor differ by which the RTC is speed up.
Comments, ideas?

