Interface PooledObject<T>
- Type Parameters:
T- the type of object being pooled - 池化对象类型
- All Known Implementing Classes:
DefaultPooledObject
public interface PooledObject<T>
PooledObject - Pooled Object Wrapper Interface
PooledObject - 池化对象包装接口
Wraps objects managed by an object pool, tracking state and timing information.
包装由对象池管理的对象,追踪状态和时间信息。
Features | 主要功能:
- Object wrapping and access - 对象包装和访问
- State management - 状态管理
- Timing information tracking - 时间信息追踪
- Borrow count statistics - 借用次数统计
Usage Examples | 使用示例:
PooledObject<Connection> pooledConn = pool.borrowPooledObject();
Connection conn = pooledConn.getObject();
Duration idle = pooledConn.getIdleDuration();
long count = pooledConn.getBorrowCount();
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Since:
- JDK 25, opencode-base-pool V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleancompareAndSetState(PooledObjectState expect, PooledObjectState update) Compares and sets the state atomically.Gets the active duration (time since last borrow).longGets the borrow count.Gets the creation instant.Gets the idle duration (time since last return).Gets the last borrow instant.Gets the last return instant.Gets the last use instant.Gets the actual pooled object.getState()Gets the current state.
-
Method Details
-
getObject
-
getCreateInstant
-
getLastBorrowInstant
Instant getLastBorrowInstant()Gets the last borrow instant. 获取最后借用时间。- Returns:
- the last borrow instant - 最后借用时间
-
getLastReturnInstant
Instant getLastReturnInstant()Gets the last return instant. 获取最后归还时间。- Returns:
- the last return instant - 最后归还时间
-
getLastUseInstant
Instant getLastUseInstant()Gets the last use instant. 获取最后使用时间。- Returns:
- the last use instant - 最后使用时间
-
getState
-
getBorrowCount
long getBorrowCount()Gets the borrow count. 获取借用次数。- Returns:
- the borrow count - 借用次数
-
getActiveDuration
Duration getActiveDuration()Gets the active duration (time since last borrow). 获取活跃时长(自上次借用以来的时间)。- Returns:
- the active duration - 活跃时长
-
getIdleDuration
Duration getIdleDuration()Gets the idle duration (time since last return). 获取空闲时长(自上次归还以来的时间)。- Returns:
- the idle duration - 空闲时长
-
compareAndSetState
Compares and sets the state atomically. 原子地比较并设置状态。- Parameters:
expect- the expected state - 期望状态update- the new state - 新状态- Returns:
- true if successful - 如果成功返回true
-