Interface LongTaskTimer

All Superinterfaces:
HistogramSupport, Meter
All Known Implementing Classes:
CumulativeHistogramLongTaskTimer, DefaultLongTaskTimer, NoopLongTaskTimer

public interface LongTaskTimer extends Meter, HistogramSupport
A long task timer is used to track the total duration of all in-flight long-running tasks and the number of such tasks.
  • Method Details

    • builder

      static LongTaskTimer.Builder builder(String name)
    • builder

      static LongTaskTimer.Builder builder(Timed timed)
      Create a timer builder from a Timed annotation.
      Parameters:
      timed - The annotation instance to base a new timer on.
      Returns:
      This builder.
    • recordCallable

      @Nullable default <T> T recordCallable(Callable<T> f) throws Exception
      Executes the callable f and records the time taken.
      Type Parameters:
      T - The return type of the Callable.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
      Throws:
      Exception - Any exception bubbling up from the callable.
    • record

      @Nullable default <T> T record(Supplier<T> f)
      Executes the supplier f and records the time taken.
      Type Parameters:
      T - The return type of the Supplier.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
    • record

      default boolean record(BooleanSupplier f)
      Executes the supplier f and records the time taken.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
      Since:
      1.10.0
    • record

      default int record(IntSupplier f)
      Executes the supplier f and records the time taken.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
      Since:
      1.10.0
    • record

      default long record(LongSupplier f)
      Executes the supplier f and records the time taken.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
      Since:
      1.10.0
    • record

      default double record(DoubleSupplier f)
      Executes the supplier f and records the time taken.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
      Since:
      1.10.0
    • record

      default void record(Consumer<LongTaskTimer.Sample> f)
      Executes the runnable f and records the time taken.
      Parameters:
      f - Function to execute and measure the execution time with a reference to the timer id useful for looking up current duration.
    • record

      default void record(Runnable f)
      Executes the runnable f and records the time taken.
      Parameters:
      f - Function to execute and measure the execution time.
    • start

      Start keeping time for a task.
      Returns:
      A task id that can be used to look up how long the task has been running.
    • duration

      double duration(TimeUnit unit)
      Parameters:
      unit - The time unit to scale the duration to.
      Returns:
      The cumulative duration of all current tasks.
    • activeTasks

      int activeTasks()
      Returns:
      The current number of tasks being executed.
    • mean

      default double mean(TimeUnit unit)
      Parameters:
      unit - The base unit of time to scale the mean to.
      Returns:
      The distribution average for all recorded events.
      Since:
      1.5.1
    • max

      double max(TimeUnit unit)
      The amount of time the longest running task has been running
      Parameters:
      unit - The time unit to scale the max to.
      Returns:
      The maximum active task duration.
      Since:
      1.5.0
    • baseTimeUnit

      TimeUnit baseTimeUnit()
      Returns:
      The base time unit of the long task timer to which all published metrics will be scaled
      Since:
      1.5.0
    • stop

      @Deprecated default long stop(long task)
      Deprecated.
      Use LongTaskTimer.Sample.stop(). As of 1.5.0, this always returns -1 as tasks no longer have IDs.
      Mark a given task as completed.
      Parameters:
      task - Id for the task to stop. This should be the value returned from start().
      Returns:
      Duration for the task in nanoseconds. A -1 value will be returned for an unknown task.
    • duration

      @Deprecated default double duration(long task, TimeUnit unit)
      Deprecated.
      Use LongTaskTimer.Sample.duration(TimeUnit). As of 1.5.0, this always returns -1 as tasks no longer have IDs.
      The current duration for an active task.
      Parameters:
      task - Id for the task to stop. This should be the value returned from start().
      unit - The time unit to scale the duration to.
      Returns:
      Duration for the task. A -1 value will be returned for an unknown task.
    • measure

      default Iterable<Measurement> measure()
      Description copied from interface: Meter
      Get a set of measurements. Should always return the same number of measurements and in the same order, regardless of the level of activity or the lack thereof.
      Specified by:
      measure in interface Meter
      Returns:
      The set of measurements that represents the instantaneous value of this meter.