T - 对象类型public class PartitionObjectPool<T> extends Object implements ObjectPool<T>
| 构造器和说明 |
|---|
PartitionObjectPool(PartitionPoolConfig config,
ObjectFactory<T> factory)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
Poolable<T> |
borrowObject()
借出对象,流程如下:
从池中取出对象
检查对象可用性
如果无可用对象,扩容池并创建新对象
继续取对象
|
void |
close() |
protected BlockingQueue<Poolable<T>> |
createBlockingQueue(PartitionPoolConfig poolConfig)
创建阻塞队列,默认为
ArrayBlockingQueue如果需要自定义队列类型,子类重写此方法 |
int |
getActiveCount()
获取已经借出的对象(正在使用的)对象数
|
int |
getIdleCount()
获取空闲对象数,即在池中的对象数
|
protected int |
getPartitionIndex(PartitionPoolConfig poolConfig)
获取当前线程被分配的分区
默认根据线程ID(TID)取分区大小余数 如果需要自定义,子类重写此方法 |
int |
getTotal()
获取持有对象总数
|
PartitionObjectPool<T> |
returnObject(Poolable<T> obj)
归还对象,流程如下:
检查对象可用性
不可用则销毁之
可用则入池
|
public PartitionObjectPool(PartitionPoolConfig config, ObjectFactory<T> factory)
config - 配置factory - 对象工厂,用于创建、验证和销毁对象public int getTotal()
getTotal 在接口中 ObjectPool<T>public int getIdleCount()
ObjectPoolgetIdleCount 在接口中 ObjectPool<T>public int getActiveCount()
ObjectPoolgetActiveCount 在接口中 ObjectPool<T>public Poolable<T> borrowObject()
ObjectPoolborrowObject 在接口中 ObjectPool<T>public PartitionObjectPool<T> returnObject(Poolable<T> obj)
ObjectPoolreturnObject 在接口中 ObjectPool<T>obj - 对象public void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionprotected BlockingQueue<Poolable<T>> createBlockingQueue(PartitionPoolConfig poolConfig)
ArrayBlockingQueuepoolConfig - 池配置protected int getPartitionIndex(PartitionPoolConfig poolConfig)
poolConfig - 池配置Copyright © 2024. All rights reserved.