Record Class EvictionPolicy.MaxAge<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.pool.policy.EvictionPolicy.MaxAge<T>
Type Parameters:
T - the pooled object type - 池化对象类型
Record Components:
maxLifetime - the maximum object lifetime - 最大对象生命周期
All Implemented Interfaces:
EvictionPolicy<T>
Enclosing interface:
EvictionPolicy<T>

public static record EvictionPolicy.MaxAge<T>(Duration maxLifetime) extends Record implements EvictionPolicy<T>
Maximum age eviction policy. 最大生命周期驱逐策略。

Evicts objects that have exceeded a maximum lifetime based on creation time. Essential for database connections that must be recycled periodically.

驱逐超过最大生命周期的对象(基于创建时间,而非空闲时间)。 对于必须定期回收的数据库连接至关重要。

Since:
JDK 25, opencode-base-pool V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • MaxAge

      public MaxAge(Duration maxLifetime)
      Creates an instance of a MaxAge record class.
      Parameters:
      maxLifetime - the value for the maxLifetime record component
  • Method Details

    • evict

      public boolean evict(PooledObject<T> obj, EvictionContext context)
      Description copied from interface: EvictionPolicy
      Determines if the object should be evicted. 确定对象是否应被驱逐。
      Specified by:
      evict in interface EvictionPolicy<T>
      Parameters:
      obj - the pooled object - 池化对象
      context - the eviction context - 驱逐上下文
      Returns:
      true if should evict - 如果应驱逐返回true
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • maxLifetime

      public Duration maxLifetime()
      Returns the value of the maxLifetime record component.
      Returns:
      the value of the maxLifetime record component