public abstract class ObjectPool<T> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
allocateCount |
protected int |
capacity |
protected BlockingQueue<T> |
queue |
| Constructor and Description |
|---|
ObjectPool(int capacity)
构造函数,初始化最大容量
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract T |
allocate()
子类重载该方法,返回一个具化类对象
|
int |
allocateCount() |
void |
drainTo(Collection<? super T> c,
int maxElements) |
boolean |
offer(T obj)
将指定的元素插入到此队列的尾部(如果立即可行且不会超过该队列的容量),
|
protected T |
poll()
获取并移除此队列的头,如果此队列为空且有未分配空间则分配一个对象,否则返回 null
|
T |
take()
获取并移除此队列的头部,在元素变得可用之前一直等待(如果有必要)
|
String |
toString() |
protected int allocateCount
protected int capacity
protected BlockingQueue<T> queue
public ObjectPool(int capacity)
capacity - 对象池最大容量public T take()
public void drainTo(Collection<? super T> c, int maxElements)
protected T poll()
public boolean offer(T obj)
在成功时返回 true,如果此队列已满,则返回 false。
protected abstract T allocate()
public int allocateCount()
Copyright © 2026. All rights reserved.