System clock changes and Java timer utilities

Discussion in 'Java' started by JKV, Feb 10, 2006.

  1. JKV

    JKV Guest

    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
     
    JKV, Feb 10, 2006
    #1
    1. Advertising

  2. JKV wrote:
    >
    > 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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Feb 10, 2006
    #2
    1. Advertising

  3. JKV

    Roedy Green Guest

    On Fri, 10 Feb 2006 11:41:56 GMT, "JKV" <jkvbe@N O S P A M y a h o o .
    c o m> wrote, quoted or indirectly quoted someone who 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 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
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Feb 10, 2006
    #3
  4. JKV

    Eric Sosman Guest

    Roedy Green wrote On 02/10/06 16:48,:
    > On Fri, 10 Feb 2006 11:41:56 GMT, "JKV" <jkvbe@N O S P A M y a h o o .
    > c o m> wrote, quoted or indirectly quoted someone who 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 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."

    --
     
    Eric Sosman, Feb 10, 2006
    #4
  5. JKV

    P.Hill Guest

    Roedy Green wrote:
    > On Fri, 10 Feb 2006 11:41:56 GMT, "JKV" <jkvbe@N O S P A M y a h o o .
    > c o m> wrote, quoted or indirectly quoted someone who 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 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


    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
     
    P.Hill, Feb 14, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valentin Tihomirov

    Are clock and divided clock synchronous?

    Valentin Tihomirov, Oct 23, 2003, in forum: VHDL
    Replies:
    11
    Views:
    3,311
    louis lin
    Oct 28, 2003
  2. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    725
    Kelsang Wangchuk
    Jul 31, 2003
  3. Replies:
    1
    Views:
    1,625
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. JKV
    Replies:
    0
    Views:
    420
  5. Replies:
    8
    Views:
    525
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page