Interface Timer


public interface Timer
Timer - A metric for measuring duration of operations Timer - 用于测量操作持续时间的指标

Timers record duration values and provide aggregated statistics such as count, total time, max, and mean.

计时器记录持续时间值并提供聚合统计信息,如计数、总时间、最大值和均值。

Since:
JDK 25, opencode-base-observability V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the number of recorded durations.
    id()
    Returns the metric identifier.
    max()
    Returns the maximum recorded duration.
    Returns the mean recorded duration.
    void
    record(Duration duration)
    Records the given duration.
    void
    time(Runnable task)
    Times the given task and records its duration.
    <T> T
    time(Callable<T> task)
    Times the given callable task and records its duration.
    Returns the total recorded time.
  • Method Details

    • record

      void record(Duration duration)
      Records the given duration. 记录给定的持续时间。
      Parameters:
      duration - the duration to record | 要记录的持续时间
      Throws:
      ObservabilityException - if duration is negative | 如果持续时间为负
    • time

      void time(Runnable task)
      Times the given task and records its duration. 计时给定任务并记录其持续时间。
      Parameters:
      task - the task to time | 要计时的任务
      Throws:
      ObservabilityException - if task is null | 如果任务为 null
    • time

      <T> T time(Callable<T> task)
      Times the given callable task and records its duration. 计时给定的可调用任务并记录其持续时间。
      Type Parameters:
      T - the return type | 返回类型
      Parameters:
      task - the task to time | 要计时的任务
      Returns:
      the task result | 任务结果
      Throws:
      ObservabilityException - if task is null or throws a checked exception | 如果任务为 null 或抛出受检异常
    • count

      long count()
      Returns the number of recorded durations. 返回已记录的持续时间数量。
      Returns:
      the count | 计数
    • totalTime

      Duration totalTime()
      Returns the total recorded time. 返回总记录时间。
      Returns:
      the total time | 总时间
    • max

      Duration max()
      Returns the maximum recorded duration. 返回最大已记录持续时间。
      Returns:
      the max duration | 最大持续时间
    • mean

      Duration mean()
      Returns the mean recorded duration. 返回平均已记录持续时间。
      Returns:
      the mean duration | 平均持续时间
    • id

      MetricId id()
      Returns the metric identifier. 返回指标标识符。
      Returns:
      the MetricId | 指标 ID