Class PoolConfig.Builder

java.lang.Object
cloud.opencode.base.pool.PoolConfig.Builder
Enclosing class:
PoolConfig

public static class PoolConfig.Builder extends Object
Builder for PoolConfig. PoolConfig构建器。
Since:
JDK 25, opencode-base-pool V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • maxTotal

      public PoolConfig.Builder maxTotal(int maxTotal)
      Sets the maximum total objects. 设置最大对象总数。
      Parameters:
      maxTotal - the max total - 最大总数
      Returns:
      this builder - 此构建器
    • maxIdle

      public PoolConfig.Builder maxIdle(int maxIdle)
      Sets the maximum idle objects. 设置最大空闲对象数。
      Parameters:
      maxIdle - the max idle - 最大空闲数
      Returns:
      this builder - 此构建器
    • minIdle

      public PoolConfig.Builder minIdle(int minIdle)
      Sets the minimum idle objects. 设置最小空闲对象数。
      Parameters:
      minIdle - the min idle - 最小空闲数
      Returns:
      this builder - 此构建器
    • maxWait

      public PoolConfig.Builder maxWait(Duration maxWait)
      Sets the maximum wait time. 设置最大等待时间。
      Parameters:
      maxWait - the max wait - 最大等待时间
      Returns:
      this builder - 此构建器
    • minEvictableIdleTime

      public PoolConfig.Builder minEvictableIdleTime(Duration duration)
      Sets the minimum evictable idle time. 设置最小可驱逐空闲时间。
      Parameters:
      duration - the duration - 时长
      Returns:
      this builder - 此构建器
    • timeBetweenEvictionRuns

      public PoolConfig.Builder timeBetweenEvictionRuns(Duration duration)
      Sets the time between eviction runs. 设置驱逐运行之间的时间。
      Parameters:
      duration - the duration - 时长
      Returns:
      this builder - 此构建器
    • numTestsPerEvictionRun

      public PoolConfig.Builder numTestsPerEvictionRun(int numTests)
      Sets the number of tests per eviction run. 设置每次驱逐运行的测试数。
      Parameters:
      numTests - the number of tests - 测试数
      Returns:
      this builder - 此构建器
    • testOnBorrow

      public PoolConfig.Builder testOnBorrow(boolean test)
      Sets whether to test on borrow. 设置是否在借用时测试。
      Parameters:
      test - true to test - 是否测试
      Returns:
      this builder - 此构建器
    • testOnReturn

      public PoolConfig.Builder testOnReturn(boolean test)
      Sets whether to test on return. 设置是否在归还时测试。
      Parameters:
      test - true to test - 是否测试
      Returns:
      this builder - 此构建器
    • testOnCreate

      public PoolConfig.Builder testOnCreate(boolean test)
      Sets whether to test on create. 设置是否在创建时测试。
      Parameters:
      test - true to test - 是否测试
      Returns:
      this builder - 此构建器
    • testWhileIdle

      public PoolConfig.Builder testWhileIdle(boolean test)
      Sets whether to test while idle. 设置是否在空闲时测试。
      Parameters:
      test - true to test - 是否测试
      Returns:
      this builder - 此构建器
    • waitPolicy

      public PoolConfig.Builder waitPolicy(WaitPolicy policy)
      Sets the wait policy. 设置等待策略。
      Parameters:
      policy - the policy - 策略
      Returns:
      this builder - 此构建器
    • lifo

      public PoolConfig.Builder lifo(boolean lifo)
      Sets LIFO ordering. 设置LIFO顺序。
      Parameters:
      lifo - true for LIFO - 是否LIFO
      Returns:
      this builder - 此构建器
    • evictionPolicy

      public PoolConfig.Builder evictionPolicy(EvictionPolicy<?> policy)
      Sets the eviction policy. 设置驱逐策略。
      Parameters:
      policy - the policy - 策略
      Returns:
      this builder - 此构建器
    • maxObjectLifetime

      public PoolConfig.Builder maxObjectLifetime(Duration maxObjectLifetime)
      Sets the maximum object lifetime before forced eviction. 设置强制驱逐前的最大对象生命周期。
      Parameters:
      maxObjectLifetime - the max lifetime (Duration.ZERO to disable) - 最大生命周期(Duration.ZERO禁用)
      Returns:
      this builder - 此构建器
    • eventListener

      public PoolConfig.Builder eventListener(PoolEventListener<?> eventListener)
      Sets the pool event listener. 设置池事件监听器。

      Type Safety Warning | 类型安全警告: The listener's type parameter must match the pool's object type <T>. Due to Java type erasure, mismatched types will not cause a compile-time error but may result in ClassCastException at runtime when listener methods are invoked.

      监听器的类型参数必须与池的对象类型 <T> 匹配。由于 Java 类型擦除, 类型不匹配不会产生编译时错误,但在调用监听器方法时可能导致 ClassCastException

      Parameters:
      eventListener - the event listener (null for none) - 事件监听器(null表示无)
      Returns:
      this builder - 此构建器
    • build

      public PoolConfig build()
      Builds the configuration. 构建配置。
      Returns:
      the config - 配置