Wpis z mikrobloga

#programista15k #java

W zookeeper jest metoda Time.currentElapsedTime(), jej implementacja z tego co znalazłem to:

return System.nanoTime() / 1000000;


i w jej opisie mamy:

public static long currentElapsedTime()


Returns time in milliseconds as does System.currentTimeMillis(), but uses elapsed time from an arbitrary epoch more like System.nanoTime(). The difference is that if somebody changes the system clock, Time.currentElapsedTime will change but nanoTime won't. On the other hand, all of ZK assumes that time is measured in milliseconds.


Returns:

The time in milliseconds from some arbitrary point in time.


Czy rozumiecie ten fragment: "The difference is that if somebody changes the system clock, Time.currentElapsedTime will change but nanoTime won't." - jak wartość Time.currentElapsedTime może się zmienić w chwili, gdy wartość nanoTime się nie zmieni? ( ͡° ʖ̯ ͡°) Czy to jest niepoprawne stwierdzenie, czy ja nie umiem w #angielski albo jestem nierozumny?

#programowanie
  • 4
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach

@a5f5c1: currentElapsedTime to odczyt bieżącego czasu systemowego, jeśli ktoś go zmieni (np synchronizacja czasu) to zmieni się też w jvmie. A nanotime jest niewrażliwy na zmiany czasu systemowego.

Tak by wychodziło z opisu
  • Odpowiedz
return System.nanoTime() / 1000000;


@sosna119: a więc jeśli nanoTime jest niewrażliwe, to jak powyższe wyrażenie (czyli implementacja metody currentElapsedTime()) może być wrażliwe?
  • Odpowiedz
@a5f5c1: Wygląda na błąd w Javadocu. Zamiast "Time.currentElapsedTime will change but nanoTime won't" powinno być "Time.currentElapsedTime will change but currentTimeMillis won't". Wtedy wszystko będzie się zgadzać.
  • Odpowiedz