Record Class PoolConfig
java.lang.Object
java.lang.Record
cloud.opencode.base.pool.PoolConfig
- Record Components:
maxTotal- maximum total objects - 最大对象总数maxIdle- maximum idle objects - 最大空闲对象数minIdle- minimum idle objects - 最小空闲对象数maxWait- maximum wait time for borrow - 借用的最大等待时间minEvictableIdleTime- minimum idle time before eviction - 驱逐前的最小空闲时间timeBetweenEvictionRuns- time between eviction runs - 驱逐运行之间的时间numTestsPerEvictionRun- number of objects to test per eviction run - 每次驱逐运行测试的对象数testOnBorrow- validate on borrow - 借用时验证testOnReturn- validate on return - 归还时验证testOnCreate- validate on create - 创建时验证testWhileIdle- validate while idle - 空闲时验证waitPolicy- wait policy when exhausted - 耗尽时的等待策略lifo- last-in-first-out ordering - 后进先出顺序evictionPolicy- eviction policy - 驱逐策略maxObjectLifetime- maximum object lifetime before forced eviction (Duration.ZERO = disabled) - 强制驱逐前的最大对象生命周期(Duration.ZERO = 禁用)eventListener- optional event listener for pool lifecycle events (null = none) - 池生命周期事件的可选事件监听器(null = 无)
public record PoolConfig(int maxTotal, int maxIdle, int minIdle, Duration maxWait, Duration minEvictableIdleTime, Duration timeBetweenEvictionRuns, int numTestsPerEvictionRun, boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle, WaitPolicy waitPolicy, boolean lifo, EvictionPolicy<?> evictionPolicy, Duration maxObjectLifetime, PoolEventListener<?> eventListener)
extends Record
PoolConfig - Pool Configuration Record (JDK 25 Record)
PoolConfig - 池配置记录 (JDK 25 Record)
Immutable configuration for object pools. Uses Record for type-safe, immutable configuration with builder pattern support.
对象池的不可变配置。使用Record实现类型安全、不可变配置,支持构建器模式。
Features | 主要功能:
- Pool size configuration - 池大小配置
- Timeout configuration - 超时配置
- Eviction configuration - 驱逐配置
- Validation configuration - 验证配置
- Builder pattern support - 构建器模式支持
Usage Examples | 使用示例:
PoolConfig config = PoolConfig.builder()
.maxTotal(20)
.maxIdle(10)
.minIdle(5)
.maxWait(Duration.ofSeconds(10))
.testOnBorrow(true)
.build();
PoolConfig defaults = PoolConfig.defaults();
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-pool V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPoolConfig(int maxTotal, int maxIdle, int minIdle, Duration maxWait, Duration minEvictableIdleTime, Duration timeBetweenEvictionRuns, int numTestsPerEvictionRun, boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle, WaitPolicy waitPolicy, boolean lifo, EvictionPolicy<?> evictionPolicy, Duration maxObjectLifetime, PoolEventListener<?> eventListener) Creates an instance of aPoolConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if blocking wait is enabled.static PoolConfig.Builderbuilder()Creates a builder for PoolConfig.static PoolConfigdefaults()Creates default configuration.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theeventListenerrecord component.Returns the value of theevictionPolicyrecord component.final inthashCode()Returns a hash code value for this object.booleanChecks if eviction is enabled.booleanChecks if maximum object lifetime eviction is enabled.booleanlifo()Returns the value of theliforecord component.intmaxIdle()Returns the value of themaxIdlerecord component.Returns the value of themaxObjectLifetimerecord component.intmaxTotal()Returns the value of themaxTotalrecord component.maxWait()Returns the value of themaxWaitrecord component.Returns the value of theminEvictableIdleTimerecord component.intminIdle()Returns the value of theminIdlerecord component.intReturns the value of thenumTestsPerEvictionRunrecord component.booleanReturns the value of thetestOnBorrowrecord component.booleanReturns the value of thetestOnCreaterecord component.booleanReturns the value of thetestOnReturnrecord component.booleanReturns the value of thetestWhileIdlerecord component.Returns the value of thetimeBetweenEvictionRunsrecord component.final StringtoString()Returns a string representation of this record class.Returns the value of thewaitPolicyrecord component.
-
Constructor Details
-
PoolConfig
public PoolConfig(int maxTotal, int maxIdle, int minIdle, Duration maxWait, Duration minEvictableIdleTime, Duration timeBetweenEvictionRuns, int numTestsPerEvictionRun, boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle, WaitPolicy waitPolicy, boolean lifo, EvictionPolicy<?> evictionPolicy, Duration maxObjectLifetime, PoolEventListener<?> eventListener) Creates an instance of aPoolConfigrecord class.- Parameters:
maxTotal- the value for themaxTotalrecord componentmaxIdle- the value for themaxIdlerecord componentminIdle- the value for theminIdlerecord componentmaxWait- the value for themaxWaitrecord componentminEvictableIdleTime- the value for theminEvictableIdleTimerecord componenttimeBetweenEvictionRuns- the value for thetimeBetweenEvictionRunsrecord componentnumTestsPerEvictionRun- the value for thenumTestsPerEvictionRunrecord componenttestOnBorrow- the value for thetestOnBorrowrecord componenttestOnReturn- the value for thetestOnReturnrecord componenttestOnCreate- the value for thetestOnCreaterecord componenttestWhileIdle- the value for thetestWhileIdlerecord componentwaitPolicy- the value for thewaitPolicyrecord componentlifo- the value for theliforecord componentevictionPolicy- the value for theevictionPolicyrecord componentmaxObjectLifetime- the value for themaxObjectLifetimerecord componenteventListener- the value for theeventListenerrecord component
-
-
Method Details
-
builder
Creates a builder for PoolConfig. 创建PoolConfig构建器。- Returns:
- the builder - 构建器
-
defaults
Creates default configuration. 创建默认配置。- Returns:
- the default config - 默认配置
-
isEvictionEnabled
public boolean isEvictionEnabled()Checks if eviction is enabled. 检查是否启用驱逐。- Returns:
- true if eviction is enabled - 如果启用驱逐返回true
-
blockWhenExhausted
public boolean blockWhenExhausted()Checks if blocking wait is enabled. 检查是否启用阻塞等待。- Returns:
- true if blocking - 如果阻塞返回true
-
isLifetimeEnabled
public boolean isLifetimeEnabled()Checks if maximum object lifetime eviction is enabled. 检查是否启用最大对象生命周期驱逐。- Returns:
- true if lifetime eviction is enabled - 如果启用生命周期驱逐返回true
-
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. -
maxTotal
-
maxIdle
-
minIdle
-
maxWait
-
minEvictableIdleTime
Returns the value of theminEvictableIdleTimerecord component.- Returns:
- the value of the
minEvictableIdleTimerecord component
-
timeBetweenEvictionRuns
Returns the value of thetimeBetweenEvictionRunsrecord component.- Returns:
- the value of the
timeBetweenEvictionRunsrecord component
-
numTestsPerEvictionRun
public int numTestsPerEvictionRun()Returns the value of thenumTestsPerEvictionRunrecord component.- Returns:
- the value of the
numTestsPerEvictionRunrecord component
-
testOnBorrow
public boolean testOnBorrow()Returns the value of thetestOnBorrowrecord component.- Returns:
- the value of the
testOnBorrowrecord component
-
testOnReturn
public boolean testOnReturn()Returns the value of thetestOnReturnrecord component.- Returns:
- the value of the
testOnReturnrecord component
-
testOnCreate
public boolean testOnCreate()Returns the value of thetestOnCreaterecord component.- Returns:
- the value of the
testOnCreaterecord component
-
testWhileIdle
public boolean testWhileIdle()Returns the value of thetestWhileIdlerecord component.- Returns:
- the value of the
testWhileIdlerecord component
-
waitPolicy
Returns the value of thewaitPolicyrecord component.- Returns:
- the value of the
waitPolicyrecord component
-
lifo
-
evictionPolicy
Returns the value of theevictionPolicyrecord component.- Returns:
- the value of the
evictionPolicyrecord component
-
maxObjectLifetime
Returns the value of themaxObjectLifetimerecord component.- Returns:
- the value of the
maxObjectLifetimerecord component
-
eventListener
Returns the value of theeventListenerrecord component.- Returns:
- the value of the
eventListenerrecord component
-