T
- 对象类型public class PartitionObjectPool<T> extends Object implements ObjectPool<T>
Constructor and Description |
---|
PartitionObjectPool(PartitionPoolConfig config,
ObjectFactory<T> factory)
构造
|
Modifier and Type | Method and Description |
---|---|
T |
borrowObject()
借出对象,流程如下:
从池中取出对象
检查对象可用性
如果无可用对象,扩容池并创建新对象
继续取对象
|
void |
close() |
protected BlockingQueue<Poolable<T>> |
createBlockingQueue(PartitionPoolConfig poolConfig)
创建阻塞队列,默认为
ArrayBlockingQueue 如果需要自定义队列类型,子类重写此方法 |
ObjectPool<T> |
free(T obj)
释放对象,即在使用中发现对象损坏或不可用,则直接销毁之
|
int |
getActiveCount()
获取已经借出的对象(正在使用的)对象数
|
int |
getIdleCount()
获取空闲对象数,即在池中的对象数
|
protected int |
getPartitionIndex(PartitionPoolConfig poolConfig)
获取当前线程被分配的分区
默认根据线程ID(TID)取分区大小余数 如果需要自定义,子类重写此方法 |
int |
getTotal()
获取持有对象总数
|
PartitionObjectPool<T> |
returnObject(T obj)
归还对象,流程如下:
检查对象可用性
不可用则销毁之
可用则入池
|
String |
toString() |
public PartitionObjectPool(PartitionPoolConfig config, ObjectFactory<T> factory)
config
- 配置factory
- 对象工厂,用于创建、验证和销毁对象public int getTotal()
getTotal
in interface ObjectPool<T>
public int getIdleCount()
ObjectPool
getIdleCount
in interface ObjectPool<T>
public int getActiveCount()
ObjectPool
getActiveCount
in interface ObjectPool<T>
public T borrowObject()
ObjectPool
borrowObject
in interface ObjectPool<T>
public PartitionObjectPool<T> returnObject(T obj)
ObjectPool
returnObject
in interface ObjectPool<T>
obj
- 对象public ObjectPool<T> free(T obj)
ObjectPool
free
in interface ObjectPool<T>
obj
- 对象public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
protected BlockingQueue<Poolable<T>> createBlockingQueue(PartitionPoolConfig poolConfig)
ArrayBlockingQueue
poolConfig
- 池配置protected int getPartitionIndex(PartitionPoolConfig poolConfig)
poolConfig
- 池配置Copyright © 2025. All rights reserved.