- All Known Implementing Classes:
ThreadPool
public interface TimeProvider
An interface encapsulating the different methods for getting relative and absolute time. The main
implementation of this is
ThreadPool. To make it clear that a
ThreadPool is being passed around only to get time, it is preferred to use this interface.-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of milliseconds since UNIX epoch.longReturns a value of milliseconds that may be used for relative time calculations.longReturns a value of milliseconds that may be used for relative time calculations.longReturns a value of nanoseconds that may be used for relative time calculations.
-
Method Details
-
relativeTimeInMillis
long relativeTimeInMillis()Returns a value of milliseconds that may be used for relative time calculations. This method should only be used for calculating time deltas. For an epoch based timestamp, seeabsoluteTimeInMillis(). -
relativeTimeInNanos
long relativeTimeInNanos()Returns a value of nanoseconds that may be used for relative time calculations. This method should only be used for calculating time deltas. For an epoch based timestamp, seeabsoluteTimeInMillis(). -
rawRelativeTimeInMillis
long rawRelativeTimeInMillis()Returns a value of milliseconds that may be used for relative time calculations. Similar torelativeTimeInMillis()except that this method is more expensive: the return value is computed directly fromSystem.nanoTime()and is not cached. You should userelativeTimeInMillis()unless the extra accuracy offered by this method is worth the costs. When computing a time interval by comparing relative times in milliseconds, you should make sure that both endpoints use cached values returned fromrelativeTimeInMillis()or that they both use raw values returned from this method. It doesn't really make sense to compare a raw value to a cached value, even if in practice the result of such a comparison will be approximately sensible. -
absoluteTimeInMillis
long absoluteTimeInMillis()Returns the value of milliseconds since UNIX epoch. This method should only be used for exact date/time formatting. For calculating time deltas that should not suffer from negative deltas, which are possible with this method, seerelativeTimeInMillis().
-