Class ScheduledTimer

  • All Implemented Interfaces:
    HeartbeatTimer

    @ThreadSafe
    public final class ScheduledTimer
    extends java.lang.Object
    implements HeartbeatTimer
    This class can be used for controlling heartbeat execution of threads. In particular, the ScheduledTimer blocks on the tick() method, waiting for someone to invoke the schedule() method. The contract of this class is that the schedule() method should only be called after the tick() was called and that there is exactly one schedule() call per tick() call. The schedule() method is not meant to be invoked directly. Instead, the HeartbeatScheduler class should be used.
    • Constructor Summary

      Constructors 
      Constructor Description
      ScheduledTimer​(java.lang.String threadName, long intervalMs)
      Creates a new instance of ScheduledTimer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getThreadName()  
      protected void schedule()
      Schedules execution of the heartbeat.
      void tick()
      Waits until next heartbeat should be executed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScheduledTimer

        public ScheduledTimer​(java.lang.String threadName,
                              long intervalMs)
        Creates a new instance of ScheduledTimer.
        Parameters:
        threadName - the thread name
        intervalMs - the heartbeat interval (unused)
    • Method Detail

      • getThreadName

        public java.lang.String getThreadName()
        Returns:
        the thread name
      • schedule

        protected void schedule()
        Schedules execution of the heartbeat.
      • tick

        public void tick()
                  throws java.lang.InterruptedException
        Description copied from interface: HeartbeatTimer
        Waits until next heartbeat should be executed.
        Specified by:
        tick in interface HeartbeatTimer
        Throws:
        java.lang.InterruptedException - if the thread is interrupted while waiting