T
- the type of objects held in this object poolpublic class ConcurrentLinkedPool<T> extends AbstractBasePoolService implements NonValidatingPoolService<T>
ConcurrentLinkedQueue
and a Semaphore
. This object pool does not implement any validation of whether the
currently restored object has been taken before that from the object pool, or whether this object
is currently in taken state.
This object pool provides support for fairness with regards to the waiting taker's threads.
The creation of new objects and their lifecycle are controlled by a supplied during the
object pool's creation time PoolObjectFactory
.
This object pool has support for shrinking (reduction) of the number of
allocated on the pool objects. Note that the shrinking may reduce the
createdTotal()
to less than the pool initialSize()
.
ConcurrentHolderLinkedPool
Constructor and Description |
---|
ConcurrentLinkedPool(PoolObjectFactory<T> poolObjectFactory,
int initialSize,
int maxSize,
boolean fair)
Creates a new
ConcurrentLinkedPool with the given
PoolObjectFactory , initial and max sizes, fairness setting. |
Modifier and Type | Method and Description |
---|---|
int |
createdTotal()
Returns the total number of created objects which currently exist for this object pool.
|
int |
initialSize()
Returns the
initialSize of this object pool at construction time. |
boolean |
isFair()
Returns the fairness setting of this object pool.
|
boolean |
isTerminated()
Returns the current terminated state of this object pool.
|
int |
maxSize()
Returns the
maxSize of this object pool. |
protected T |
newObject() |
int |
reduceCreated(int reduction,
boolean ignoreInitialSize)
Tries to remove (and destroy) up to
reduction objects from the object pool. |
int |
remainingCapacity()
Returns the remaining capacity of this object pool, i.e.
|
void |
restore(T object)
Restores (returns) an object to the object pool.
|
void |
restore(T object,
boolean valid)
Restores (returns) an object to the object pool.
|
T |
take()
Takes an object from the object pool if there is such available.
|
T |
takeUninterruptibly()
Takes an object from the object pool if there is such available.
|
void |
terminate()
Terminates this object pool.
|
T |
tryTake()
Tries to take an object from the object pool if there is one which is immediately available.
|
T |
tryTake(long timeout,
TimeUnit unit)
Takes an object from the object pool if there is such available.
|
drainCreated, remainingCreated, taken, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
drainCreated, remainingCreated, taken
public ConcurrentLinkedPool(PoolObjectFactory<T> poolObjectFactory, int initialSize, int maxSize, boolean fair)
ConcurrentLinkedPool
with the given
PoolObjectFactory
, initial and max sizes, fairness setting.poolObjectFactory
- the factory which will be used to create new objects
in this object pool as well as to control their lifecycleinitialSize
- the object pool initial size, i.e. the initial number of
allocated in the object pool objectsmaxSize
- the object pool max size, i.e. the max number of allocated
in the object pool objectsfair
- the object pool's fairness setting with regards to waiting threadsIllegalArgumentException
- if one of the following holds:initialSize < 0 || maxSize < 1 || maxSize < initialSize
NullPointerException
- if poolObjectFactory
is nullpublic T take()
null
and the thread's interrupted status will
be set to true
.take
in interface NonValidatingPoolService<T>
null
if was interrupted while waitingpublic T takeUninterruptibly()
takeUninterruptibly
in interface NonValidatingPoolService<T>
public T tryTake(long timeout, TimeUnit unit)
timeout
for an object to become available. If the calling
thread is interrupted while waiting this call will return null
and the thread's
interrupted status will be set to true
.tryTake
in interface NonValidatingPoolService<T>
timeout
- the maximum time to wait for an object to become available in the object poolunit
- the time unit of the timeout
argumentnull
if the specified timeout expires
or if it was interrupted while waitingpublic T tryTake()
null
if no object is available at the moment of the call.tryTake
in interface NonValidatingPoolService<T>
null
if there is no object available in the object poolprotected T newObject()
public void restore(T object)
restore(Object, true)
.restore
in interface NonValidatingPoolService<T>
object
- an object to be restored (returned) to this object poolpublic void restore(T object, boolean valid)
restore
in interface NonValidatingPoolService<T>
object
- an object to be restored (returned) to this object poolvalid
- if true
the restored object is presumed to be in valid (healthy) state,
otherwise it is treated as invalidpublic int createdTotal()
BasePoolService.taken()
+ BasePoolService.remainingCreated()
.
Typically used for testing an debugging purposes.createdTotal
in interface BasePoolService
public int remainingCapacity()
BasePoolService.remainingCreated()
.
Typically used for testing an debugging purposes.remainingCapacity
in interface BasePoolService
public int initialSize()
initialSize
of this object pool at construction time.
This parameter never changes.initialSize
in interface BasePoolService
initialSize
public int maxSize()
maxSize
of this object pool. This parameter never changes.maxSize
in interface BasePoolService
maxSize
public int reduceCreated(int reduction, boolean ignoreInitialSize)
reduction
objects from the object pool.
May bring the object pool's BasePoolService.createdTotal()
to less then its BasePoolService.initialSize()
.reduceCreated
in interface BasePoolService
reduction
- the desired amount of objects to be removedignoreInitialSize
- specifies whether the BasePoolService.createdTotal()
may be
reduced to less than BasePoolService.initialSize()
public void terminate()
terminate
in interface BasePoolService
public boolean isTerminated()
isTerminated
in interface BasePoolService
true
if the object pool is terminatedpublic boolean isFair()
isFair
in interface BasePoolService
true
if the object pool is fair to waiting taker threadsCopyright © 2013-2014 Simeon Malchev. All Rights Reserved.