System clock changes and Java timer utilities

J

JKV

Hi,

If the system clock is changed backward or forward what is the expected
result on calls like Object.wait, Thread.sleep and scheduled timers in Java
1.5?

Does the underlying implementation use System.currentTimeMillis or similar
or does it count the clock ticks?

Is it hardware or OS dependent?

Thanks,

Jan
 
T

Thomas Hawtin

JKV said:
If the system clock is changed backward or forward what is the expected
result on calls like Object.wait, Thread.sleep and scheduled timers in Java
1.5?

It shouldn't do.

Having said that, the specification is loose. There is no guarantee on
the accuracy of the interval. 1.5 clarifies the specification of wait to
allow it to return spuriously, even without an interval set.
Does the underlying implementation use System.currentTimeMillis or similar
or does it count the clock ticks?

1.5 has System.nanoTime, which again shouldn't be upset by changes in
the system clock.

java.util.Timer and, IIRC, javax.swing.Timer use
System.currentTimeMillis, so may exhibit incorrect behaviour.
Is it hardware or OS dependent?

Bugs can be. I found (on, IIRC, Fedora Core 4 on a PII) that
System.nanoTime jumped about when I changed the system clock.

Tom Hawtin
 
E

Eric Sosman

Roedy Green wrote On 02/10/06 16:48,:
it screws up! Timers work by recording the wakeup absolute time.

I ran into this problem writing setclock, which resets your clock. See
http://mindprod.com/webstarts/setclock.html

For all the derision directed at (Open)VMS, this is
something it did/does better than the systems that have
largely supplanted it. Times could be stated as "absolute"
or "relative;" the former were affected by changes to the
system clock while the latter were not. You used whichever
made sense for the need at hand: absolute for "at noon,"
relative for "ten-second timeout."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top