Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

System clock changes and Java timer utilities

Thread view: 
JKV - 10 Feb 2006 11:41 GMT
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
Thomas Hawtin - 10 Feb 2006 14:45 GMT
> 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
Signature

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

Roedy Green - 10 Feb 2006 21:48 GMT
>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 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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Eric Sosman - 10 Feb 2006 22:07 GMT
Roedy Green wrote On 02/10/06 16:48,:

>>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
[quoted text clipped - 4 lines]
> 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."

Signature

Eric.Sosman@sun.com

P.Hill - 14 Feb 2006 05:14 GMT
>>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
[quoted text clipped - 4 lines]
> I ran into this problem writing setclock, which resets your clock. See
> http://mindprod.com/webstarts/setclock.html

Technically SNTP does NOT push time into the past.  It slews the time
slowly, see an old page I wrote on that subject.

http://www.xmission.com/~goodhill/dates/increasingmillisecond.html

I'm not sure what that means for setting the clock via Java...

-Paul


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.