Class TimeService

java.lang.Object
org.jgroups.util.TimeService
All Implemented Interfaces:
Runnable

public class TimeService extends Object implements 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
  • Field Details

    • timer

      protected TimeScheduler timer
    • task

      protected Future<?> task
    • interval

      protected long interval
    • timestamp

      protected volatile long timestamp
    • lock

      protected final Lock lock
  • Constructor Details

  • Method Details

    • timestamp

      public long timestamp()
      Returns the timestamp (ns). Because timestamp is volatile, the read will return the result of the most recent write
      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()
    • start

      public TimeService start()
    • stop

      public TimeService stop()
    • run

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

      public String toString()
      Overrides:
      toString in class Object