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 TypeMethodDescriptionlongcount()Returns the number of recorded durations.id()Returns the metric identifier.max()Returns the maximum recorded duration.mean()Returns the mean recorded duration.voidRecords the given duration.voidTimes the given task and records its duration.<T> TTimes the given callable task and records its duration.Returns the total recorded time.
-
Method Details
-
record
Records the given duration. 记录给定的持续时间。- Parameters:
duration- the duration to record | 要记录的持续时间- Throws:
ObservabilityException- if duration is negative | 如果持续时间为负
-
time
Times the given task and records its duration. 计时给定任务并记录其持续时间。- Parameters:
task- the task to time | 要计时的任务- Throws:
ObservabilityException- if task is null | 如果任务为 null
-
time
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
-
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
-