Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6458294

nanoTime affected by system clock change on Linux (RH9) or in general lacks monotonicity

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux, windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
      Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b43)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b43, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      System.nanotTime is documented as indicating time elapsed sinse some *fixed* point. However, under Linux (RedHat 9) it is affected by changes to the system time.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code below, which displays currentTimeMillis and nanoTime approximately once a second. Change the system clock (e.g. with /sbin/hwclock --date "..." --set; /sbin/hwclock --hctosys).



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1121957273144 - 1121957273144598000
      1121957274154 - 1121957274154429000
      1121957630244 - 1121957275244934000
      1121957631254 - 1121957276254933000

      ACTUAL -
      1121957273144 - 1121957273144598000
      1121957274154 - 1121957274154429000
      1121957630244 - 1121957630244934000
      1121957631254 - 1121957631254933000


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class ShowTimes {
          public static synchronized void main(String[] args) throws Throwable {
              for (;;) {
                  ShowTimes.class.wait(1000);
                  System.out.println(
                      System.currentTimeMillis() + " - " +
                      System.nanoTime()
                  );
              }
         }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            dholmes David Holmes
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: