James' solution is based on System.nanoTime() which has a monotonical increasing behavior.
There's really no need for nano precision or resolution, and its value bears no relation to any actual calendar time or epoch. However, it's perfect to measure monotonically increasing elapsed time in order to expire space entries, for example.
His fix was important to avoid bugs in cases where the system clock (as typically given by System.currentTimeMillis() in the older implementation) may run backward because of daylight saving adjustments, or other weird NTP behavior.
However, I found the implementation a bit confusing, with unneeded usage of Duration to store "points in time" and complicated Duration operations. The complexity may have prevented the original merge of the PR, but it's still an important fix.
I attempted to go simpler, using naked System.nanoTime() and basic arithmetic as much as I could.
(there are other similar PRs for other classes that mesure elapsed time that will get fixed soon, if this is accepted)
This is a resurrection of an old PR https://github.com/jpos/jPOS/pull/418/ by James Hilliard.
James' solution is based on
System.nanoTime()
which has a monotonical increasing behavior. There's really no need for nano precision or resolution, and its value bears no relation to any actual calendar time or epoch. However, it's perfect to measure monotonically increasing elapsed time in order to expire space entries, for example.His fix was important to avoid bugs in cases where the system clock (as typically given by
System.currentTimeMillis()
in the older implementation) may run backward because of daylight saving adjustments, or other weird NTP behavior.However, I found the implementation a bit confusing, with unneeded usage of
Duration
to store "points in time" and complicatedDuration
operations. The complexity may have prevented the original merge of the PR, but it's still an important fix.I attempted to go simpler, using naked
System.nanoTime()
and basic arithmetic as much as I could.(there are other similar PRs for other classes that mesure elapsed time that will get fixed soon, if this is accepted)