|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstormpot.bpool.BlazePool<T>
T
- The type of Poolable
managed by this pool.public final class BlazePool<T extends Poolable>
BlazePool is a highly optimised LifecycledResizablePool
implementation that consists of a queues of Poolable instances, the access
to which is made faster with clever use of ThreadLocals.
Object allocation always happens in a dedicated thread, off-loading the cost of allocating the pooled objects. This should lead to reduced deviation in the times it takes claim method to complete, provided the pool is not depleted.
Constructor Summary | |
---|---|
BlazePool(Config<T> config)
Construct a new BlazePool instance based on the given Config . |
Method Summary | |
---|---|
T |
claim(Timeout timeout)
Claim the exclusive rights until released, to an object in the pool. |
int |
getTargetSize()
Get the currently configured target size of the pool. |
void |
setTargetSize(int size)
Set the target size for this pool. |
Completion |
shutdown()
Initiate the shut down process on this pool, and return a Completion instance representing the shut down procedure. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BlazePool(Config<T> config)
Config
.
config
- The pool configuration to use.Method Detail |
---|
public T claim(Timeout timeout) throws PoolException, InterruptedException
Pool
Timeout
instance, for one to become available if the
pool has been depleted. If the timeout elapses before an object can be
claimed, then null
is returned instead. The timeout will be
honoured even if the Allocators allocate
methods blocks forever. If the given timeout has a zero or negative value,
then the method will not wait.
If the current thread has already one or more objects currently claimed, then a distinct object will be returned, if one is or becomes available. This means that it is possible for a single thread to deplete the pool, if it so desires.
This method may throw a PoolException if the pool have trouble allocating
objects. That is, if its assigned Allocator throws exceptions from its
allocate method, or returns null
.
An InterruptedException
will be thrown if the thread has its
interrupted flag set upon entry to this method, or is interrupted while
waiting. The interrupted flag on the thread will be cleared after
this, as per the general contract of interruptible methods.
If the pool is a LifecycledPool
and has been shut down, then an
IllegalStateException
will be thrown when this method is called.
Likewise if we are waiting for an object to become available, and someone
shuts the pool down.
Memory effects:
release
of an object happens-before
any subsequent claim or deallocation
of that object, and,
allocation
of an object
happens-before any claim of that object.
claim
in interface Pool<T extends Poolable>
timeout
- The timeout of the maximum permitted time-slice to wait for
an object to become available. A timeout with a value of zero or less
means that the call will do no waiting, preferring instead to return early
if no objects are available.
null
if the timeout period elapsed
before an object became available.
PoolException
- If an object allocation failed because the Allocator
threw an exception from its allocate method, or returned
null
.
InterruptedException
- if the current thread is
interrupted
upon entry, or becomes interrupted
while waiting.public Completion shutdown()
LifecycledPool
Completion
instance representing the shut down procedure.
The shut down process is asynchronous, and the shutdown method is
guaranteed to not wait for any claimed Poolables
to
be released.
The shut down process cannot complete before all Poolables are released
back into the pool and deallocated
,
and all internal resources (such as threads, for instance) have been
released as well. Only when all of these things have been taken care of,
does the await methods of the Completion return.
Once the shut down process has been initiated, that is, as soon as this
method is called, the pool can no longer be used and all calls to
Pool.claim(Timeout)
will throw an IllegalStateException
.
Threads that are already waiting for objects in the claim method, will
also wake up and receive an IllegalStateException
.
All objects that are already claimed when this method is called,
will continue to function until they are
released
.
The shut down process is guaranteed to never deallocate objects that are currently claimed. Their deallocation will wait until they are released.
shutdown
in interface LifecycledPool<T extends Poolable>
Completion
instance that represents the shut down
process.public void setTargetSize(int size)
ResizablePool
If the new target size is greater than the old one, the pool will allocate more objects until it reaches the target size. If, on the other hand, the new target size is less than the old one, the pool will deallocate more and allocate less, until the new target size is reached.
No guarantees are made about when the pool actually reaches the target size. In fact, it may never happen as the target size can be changed as often as one sees fit.
Pools that do not support a size less than 1 (which would deviate from the
standard configuration space) will throw an
IllegalArgumentException
if passed 0 or less.
setTargetSize
in interface ResizablePool<T extends Poolable>
size
- The new target size of the poolpublic int getTargetSize()
ResizablePool
getTargetSize
in interface ResizablePool<T extends Poolable>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |