T - The type of resource this pool manages.public abstract class ResourcePool<T> extends Object
tachyon.client.file.FileSystemMasterClientPool as an example.| Modifier and Type | Field and Description |
|---|---|
protected Object |
mCapacityLock |
protected int |
mCurrentCapacity |
protected int |
mMaxCapacity |
protected BlockingQueue<T> |
mResources |
| Modifier | Constructor and Description |
|---|---|
|
ResourcePool(int maxCapacity)
Creates a
ResourcePool instance with the specified capacity. |
protected |
ResourcePool(int maxCapacity,
BlockingQueue<T> resources)
Internal constructor that can provide an object to be used for the internal queue.
|
| Modifier and Type | Method and Description |
|---|---|
T |
acquire()
Acquires an object of type
T from the pool. |
abstract void |
close()
Closes the resource pool.
|
protected abstract T |
createNewResource()
Creates a new resource which will be added to the resource pool after the user is done using
it.
|
void |
release(T resource)
Releases an object of type T, this must be called after the thread is done using a resource
obtained by acquire.
|
protected final Object mCapacityLock
protected final int mMaxCapacity
protected final BlockingQueue<T> mResources
protected int mCurrentCapacity
public ResourcePool(int maxCapacity)
ResourcePool instance with the specified capacity.maxCapacity - The maximum of resources in this pool.protected ResourcePool(int maxCapacity,
BlockingQueue<T> resources)
maxCapacity - The maximum of resources in this pool.resources - Blocking queue to use.public T acquire()
T from the pool. This operation is blocking if no resource
is available. Each call of acquire() should be paired with another call of
release(T) after the use of this resource completes to return this resource to the pool.public abstract void close()
public void release(T resource)
resource - the resource to be released, it should not be reused after calling this methodprotected abstract T createNewResource()
Copyright © 2015. All Rights Reserved.