Class TimeService

  • All Implemented Interfaces:
    java.lang.Runnable

    public class TimeService
    extends java.lang.Object
    implements java.lang.Runnable
    Provides a coarse grained time service. Registers a timer task which calls and caches System.nanoTime() and returns the cached value. This is way faster than calling System.nanoTime() many times, e.g. for each received message. The granularity (interval) can be chosen by the user.

    Note that use of values returned by timestamp() needs to obey the same rules as for System.nanoTime()

    Since:
    3.5
    Author:
    Bela Ban
    • Field Detail

      • task

        protected volatile java.util.concurrent.Future<?> task
      • interval

        protected long interval
      • timestamp

        protected volatile long timestamp
    • Constructor Detail

      • TimeService

        public TimeService​(TimeScheduler timer,
                           long interval)
    • Method Detail

      • timestamp

        public long timestamp()
        Returns the timestamp (ns)
        Returns:
        the result of the last call to System.nanoTime() (ns)
      • interval

        public long interval()
      • interval

        public TimeService interval​(long interval)
      • running

        public boolean running()
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object