Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-478

StopWatch does not resist to system time changes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3
    • 3.0
    • lang.time.*
    • None
    • all operating systems.

    Description

      org.apache.commons.lang.time.StopWatch seems to be relying on wall clock, i.e. by calling java.lang.System.currentTimeMillis() to sample current time.

      When a system time change occurs (user action, NTP synchronization...) between 2 calls to StopWatch.getTime(), the difference between the 2 samples is wrong: the measured duration may noticeably differ from the real one. Moreover, should the system time change consist in a backward adjustment, the difference could be negative.

      In order to make StopWatch resistant to system time changes, would it be possible to use the process time, i.e. by making implementation calling java.lang.System.nanoTime() -multiplied by appropriate factor, of course.

      Thanks a lot,
      Regis.

      Attachments

        1. LANG-478.patch
          4 kB
          Henri Yandell

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rdesgroppes Regis Desgroppes
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: