a5f5c1
a5f5c1
#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
  • Najlepsze
  • Wszystkie komentarze
sosna119
@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
tylko_zerknalem
tylko_zerknalem
@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ć.
Krolik
Krolik
@a5f5c1: mnie też wygląda na błąd w Javadocu
a5f5c1
a5f5c1
a5f5c1 Autor
0
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?