Record Class LockStats
java.lang.Object
java.lang.Record
cloud.opencode.base.lock.metrics.LockStats
- Record Components:
acquireCount- total number of lock acquisitions | 锁获取总次数releaseCount- total number of lock releases | 锁释放总次数timeoutCount- number of acquisition timeouts | 获取超时次数contentionCount- number of times threads had to wait | 线程等待次数averageWaitTime- average time spent waiting for lock | 等待锁的平均时间maxWaitTime- maximum time spent waiting for lock | 等待锁的最大时间currentHoldCount- current number of holds | 当前持有次数timestamp- time when snapshot was taken | 快照拍摄时间
public record LockStats(long acquireCount, long releaseCount, long timeoutCount, long contentionCount, Duration averageWaitTime, Duration maxWaitTime, int currentHoldCount, Instant timestamp)
extends Record
Lock Statistics Record - Immutable Snapshot of Lock Metrics
锁统计记录 - 锁指标的不可变快照
An immutable snapshot of lock statistics at a point in time, providing calculated rates for analysis.
在某个时间点锁统计的不可变快照,提供用于分析的计算率。
Features | 主要功能:
- Immutable statistics snapshot - 不可变统计快照
- Success rate calculation - 成功率计算
- Contention rate calculation - 竞争率计算
- Timeout rate calculation - 超时率计算
- Timestamp for tracking - 用于跟踪的时间戳
Usage Examples | 使用示例:
LockStats stats = metrics.snapshot();
// Check rates | 检查率
if (stats.getContentionRate() > 0.5) {
System.out.println("High contention detected!");
}
// Get timing info | 获取时间信息
System.out.println("Max wait: " + stats.maxWaitTime());
System.out.println("Snapshot at: " + stats.timestamp());
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-lock V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of theacquireCountrecord component.Returns the value of theaverageWaitTimerecord component.longReturns the value of thecontentionCountrecord component.intReturns the value of thecurrentHoldCountrecord component.final booleanIndicates whether some other object is "equal to" this one.doubleCalculates the lock contention rate 计算锁竞争率doubleCalculates the lock acquisition success rate 计算锁获取成功率doubleCalculates the lock acquisition timeout rate 计算锁获取超时率final inthashCode()Returns a hash code value for this object.Returns the value of themaxWaitTimerecord component.longReturns the value of thereleaseCountrecord component.longReturns the value of thetimeoutCountrecord component.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
LockStats
public LockStats(long acquireCount, long releaseCount, long timeoutCount, long contentionCount, Duration averageWaitTime, Duration maxWaitTime, int currentHoldCount, Instant timestamp) Creates an instance of aLockStatsrecord class.- Parameters:
acquireCount- the value for theacquireCountrecord componentreleaseCount- the value for thereleaseCountrecord componenttimeoutCount- the value for thetimeoutCountrecord componentcontentionCount- the value for thecontentionCountrecord componentaverageWaitTime- the value for theaverageWaitTimerecord componentmaxWaitTime- the value for themaxWaitTimerecord componentcurrentHoldCount- the value for thecurrentHoldCountrecord componenttimestamp- the value for thetimestamprecord component
-
-
Method Details
-
getSuccessRate
public double getSuccessRate()Calculates the lock acquisition success rate 计算锁获取成功率- Returns:
- success rate (0.0 to 1.0) | 成功率(0.0到1.0)
-
getContentionRate
public double getContentionRate()Calculates the lock contention rate 计算锁竞争率- Returns:
- contention rate (0.0 to 1.0) | 竞争率(0.0到1.0)
-
getTimeoutRate
public double getTimeoutRate()Calculates the lock acquisition timeout rate 计算锁获取超时率- Returns:
- timeout rate (0.0 to 1.0) | 超时率(0.0到1.0)
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
acquireCount
public long acquireCount()Returns the value of theacquireCountrecord component.- Returns:
- the value of the
acquireCountrecord component
-
releaseCount
public long releaseCount()Returns the value of thereleaseCountrecord component.- Returns:
- the value of the
releaseCountrecord component
-
timeoutCount
public long timeoutCount()Returns the value of thetimeoutCountrecord component.- Returns:
- the value of the
timeoutCountrecord component
-
contentionCount
public long contentionCount()Returns the value of thecontentionCountrecord component.- Returns:
- the value of the
contentionCountrecord component
-
averageWaitTime
Returns the value of theaverageWaitTimerecord component.- Returns:
- the value of the
averageWaitTimerecord component
-
maxWaitTime
Returns the value of themaxWaitTimerecord component.- Returns:
- the value of the
maxWaitTimerecord component
-
currentHoldCount
public int currentHoldCount()Returns the value of thecurrentHoldCountrecord component.- Returns:
- the value of the
currentHoldCountrecord component
-
timestamp
-