git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] activemq-artemis issue #2481: ARTEMIS-2213 don't expire critical component i...


Github user wy96f commented on the issue:

    https://github.com/apache/activemq-artemis/pull/2481
  
    @michaelandrepearce @franz1981 
    Here is the code of System::nanoTime from openjdk:
    jlong os::javaTimeNanos() {
      if (Linux::supports_monotonic_clock()) {
        struct timespec tp;
        int status = Linux::clock_gettime(CLOCK_MONOTONIC, &tp);
        assert(status == 0, "gettime error");
        jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec);
        return result;
      } else {
        timeval time;
        int status = gettimeofday(&time, NULL);
        assert(status != -1, "linux error");
        jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec);
        return 1000 * usecs;
      }
    }
    
    If monotonic clock is not supported, nanoTime is implemented like currentTimeMillis.
    If clock_gettime is used, as man page says: CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific) similar to CLOCK_MONOTONIC, but provides access to a raw hardware-based time that is not subject to NTP adjustments. That's to say CLOCK_MONOTONIC maybe affected by ntp. See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8006942, https://github.com/rust-lang/rust/issues/37902 for reference. Not sure CLOCK_MONOTONIC won't jump backward, please correct me if anything wrong:)


---