| 程序包 | 说明 |
|---|---|
| org.dromara.hutool.core.pool |
对象池封装实现
整体参考了: https://github.com/DanielYWoo/fast-object-pool/ https://github.com/apache/commons-pool |
| org.dromara.hutool.core.pool.partition |
基于分区的对象池实现,参考:https://github.com/DanielYWoo/fast-object-pool
|
| 限定符和类型 | 方法和说明 |
|---|---|
Poolable<T> |
ObjectPool.borrowObject()
借出对象,流程如下:
从池中取出对象
检查对象可用性
如果无可用对象,扩容池并创建新对象
继续取对象
|
| 限定符和类型 | 方法和说明 |
|---|---|
ObjectPool<T> |
ObjectPool.returnObject(Poolable<T> obj)
归还对象,流程如下:
检查对象可用性
不可用则销毁之
可用则入池
|
| 限定符和类型 | 类和说明 |
|---|---|
class |
PartitionPoolable<T>
分区可池化对象,此对象会同时持有原始对象和所在的分区
|
| 限定符和类型 | 方法和说明 |
|---|---|
Poolable<T> |
PoolPartition.borrowObject() |
Poolable<T> |
PartitionObjectPool.borrowObject() |
protected Poolable<T> |
PoolPartition.createPoolable()
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected BlockingQueue<Poolable<T>> |
PartitionObjectPool.createBlockingQueue(PartitionPoolConfig poolConfig)
创建阻塞队列,默认为
ArrayBlockingQueue如果需要自定义队列类型,子类重写此方法 |
| 限定符和类型 | 方法和说明 |
|---|---|
PoolPartition<T> |
PoolPartition.free(Poolable<T> obj)
销毁对象,注意此方法操作的对象必须在队列外
|
PoolPartition<T> |
PoolPartition.returnObject(Poolable<T> poolable)
归还对象
|
PartitionObjectPool<T> |
PartitionObjectPool.returnObject(Poolable<T> obj) |
| 构造器和说明 |
|---|
PoolPartition(PoolConfig config,
BlockingQueue<Poolable<T>> queue,
ObjectFactory<T> objectFactory)
构造
|
Copyright © 2024. All rights reserved.