Interface TimeProvider

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 Type
    Method
    Description
    long
    Returns the value of milliseconds since UNIX epoch.
    long
    Returns a value of milliseconds that may be used for relative time calculations.
    long
    Returns a value of milliseconds that may be used for relative time calculations.
    long
    Returns 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, see absoluteTimeInMillis().
    • 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, see absoluteTimeInMillis().
    • rawRelativeTimeInMillis

      long rawRelativeTimeInMillis()
      Returns a value of milliseconds that may be used for relative time calculations. Similar to relativeTimeInMillis() except that this method is more expensive: the return value is computed directly from System.nanoTime() and is not cached. You should use relativeTimeInMillis() 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 from relativeTimeInMillis() 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, see relativeTimeInMillis().