Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a resurrection of an old PR #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)