Class Timer


  • class Timer
    extends java.lang.Object
    The Timer object is used to set the time a specific event occurred at. The time can be set only once from that point on all attempts to set the time are ignored. This makes this timer useful when there is a desire to record when a certain scenario was first encountered, for example when a request is first read from the underlying transport.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long time
      This is the time in milliseconds used to record the event.
      private java.util.concurrent.TimeUnit unit
      This is the time unit that this timer provides the time in.
    • Constructor Summary

      Constructors 
      Constructor Description
      Timer​(java.util.concurrent.TimeUnit unit)
      Constructor for the Timer object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long get()
      This is used to get the time for a specific event.
      boolean isSet()
      This is used to determine if the timer has been set.
      void set()
      This is used to set the time for a specific event.
      • Methods inherited from class java.lang.Object

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

      • unit

        private java.util.concurrent.TimeUnit unit
        This is the time unit that this timer provides the time in.
      • time

        private volatile long time
        This is the time in milliseconds used to record the event.
    • Constructor Detail

      • Timer

        public Timer​(java.util.concurrent.TimeUnit unit)
        Constructor for the Timer object. This is used to record when a specific event occurs. The provided time unit is used to determine how the time is retrieved.
        Parameters:
        unit - this time unit this timer will be using
    • Method Detail

      • isSet

        public boolean isSet()
        This is used to determine if the timer has been set. If the set method has been called on this instance before then this will return true, otherwise false.
        Returns:
        this returns true if the timer has been set
      • set

        public void set()
        This is used to set the time for a specific event. Invoking this method multiple times will have no effect as the time is set for the first invocation only. Setting the time in this manner enables start times to be recorded effectively.
      • get

        public long get()
        This is used to get the time for a specific event. The time returned by this method is given in the time unit specified on construction of the instance.
        Returns:
        this returns the time recorded by the timer