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 Details

    • LockStats

      public LockStats(long acquireCount, long releaseCount, long timeoutCount, long contentionCount, Duration averageWaitTime, Duration maxWaitTime, int currentHoldCount, Instant timestamp)
      Creates an instance of a LockStats record class.
      Parameters:
      acquireCount - the value for the acquireCount record component
      releaseCount - the value for the releaseCount record component
      timeoutCount - the value for the timeoutCount record component
      contentionCount - the value for the contentionCount record component
      averageWaitTime - the value for the averageWaitTime record component
      maxWaitTime - the value for the maxWaitTime record component
      currentHoldCount - the value for the currentHoldCount record component
      timestamp - the value for the timestamp record 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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • acquireCount

      public long acquireCount()
      Returns the value of the acquireCount record component.
      Returns:
      the value of the acquireCount record component
    • releaseCount

      public long releaseCount()
      Returns the value of the releaseCount record component.
      Returns:
      the value of the releaseCount record component
    • timeoutCount

      public long timeoutCount()
      Returns the value of the timeoutCount record component.
      Returns:
      the value of the timeoutCount record component
    • contentionCount

      public long contentionCount()
      Returns the value of the contentionCount record component.
      Returns:
      the value of the contentionCount record component
    • averageWaitTime

      public Duration averageWaitTime()
      Returns the value of the averageWaitTime record component.
      Returns:
      the value of the averageWaitTime record component
    • maxWaitTime

      public Duration maxWaitTime()
      Returns the value of the maxWaitTime record component.
      Returns:
      the value of the maxWaitTime record component
    • currentHoldCount

      public int currentHoldCount()
      Returns the value of the currentHoldCount record component.
      Returns:
      the value of the currentHoldCount record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component