Interface PoolService<T>
- Type Parameters:
T- the type of objects held in this object pool
- All Superinterfaces:
AutoCloseable,BasePool
- All Known Implementing Classes:
ConcurrentPool
take and restore pool
methods.
This pool enforces a maximum limit on the number of objects that can be contained or taken out
of it at any time. The pool may lazily create an object upon take request; not all objects need
to exist and be valid in the pool at all times. The restore methods do not provide any validation
whether the currently restored object has been taken before that from the pool or whether it is in taken state.
Correct usage of the restore operations is established by programming convention in the application.
The object pool implementation may support an optional fairness parameter (usually provided via the
pool constructor) that defines the pool behaviour with regard to waiting takers threads, as well as
an optional Listener interface which methods will be called when a take or
restore pool method executes.
The pool cannot contain null objects.
- Author:
- Simeon Malchev
-
Method Summary
Modifier and TypeMethodDescriptionbooleanisFair()Returns the fairness setting of this object pool.listener()Returns theListenerinterface instance associated with this object pool, if any.voidRestores (returns) an object to the object pool.voidRestores (returns) an object to the object pool.take()A counterpart oftake(long[])that does not report back the time waited to obtain an object from the pool.take(long[] waitedNanos) Takes an object from the object pool if there is such available.A counterpart oftakeUninterruptibly(long[])that does not report back the time waited to obtain an object from the pool.takeUninterruptibly(long[] waitedNanos) Takes an object from the object pool if there is such available.tryTake()Tries to take an object from the object pool if there is one that is immediately available; the object may need to be created as described intryTake(long, TimeUnit, long[]).A counterpart oftryTake(long, TimeUnit, long[])that does not report back the time waited to obtain an object from the pool.Tries to take an object from the object pool if there is one available.Methods inherited from interface org.vibur.objectpool.BasePool
close, createdTotal, drainCreated, initialSize, isTerminated, maxSize, reduceCreatedBy, reduceCreatedTo, remainingCapacity, remainingCreated, taken, terminate
-
Method Details
-
take
T take()A counterpart oftake(long[])that does not report back the time waited to obtain an object from the pool.- Returns:
- an object taken from the object pool or
nullif was interrupted while waiting
-
take
Takes an object from the object pool if there is such available. This is a blocking call that waits indefinitely until an object becomes available; the object may need to be created as described intryTake(long, TimeUnit, long[]). If the calling thread is interrupted while waiting this call will returnnulland the thread's interrupted status will be set totrue.- Parameters:
waitedNanos- used to report the time waited, seetryTake(long, TimeUnit, long[])- Returns:
- an object taken from the object pool or
nullif it was interrupted while waiting
-
takeUninterruptibly
T takeUninterruptibly()A counterpart oftakeUninterruptibly(long[])that does not report back the time waited to obtain an object from the pool.- Returns:
- an object taken from the object pool
-
takeUninterruptibly
Takes an object from the object pool if there is such available. This is a blocking call that waits indefinitely until an object becomes available; the object may need to be created as described intryTake(long, TimeUnit, long[]).- Parameters:
waitedNanos- used to report the time waited, seetryTake(long, TimeUnit, long[])- Returns:
- an object taken from the object pool
-
tryTake
A counterpart oftryTake(long, TimeUnit, long[])that does not report back the time waited to obtain an object from the pool.- Parameters:
timeout- the maximum time to wait for an object to become available in the object pool; this timeout does not include the object creation time, see aboveunit- the time unit of thetimeoutargument- Returns:
- an object taken from the object pool or
nullif the specified timeout expires or if it was interrupted while waiting
-
tryTake
Tries to take an object from the object pool if there is one available. This is a blocking call that waits for an object to become available up to the specifiedtimeout. The real time spent waiting is reported back via thewaitedNanosparameter. The total method execution time may also include the object creation time - an object can be (lazily) created in the pool when the pool capacity is not reached yet but no ready and valid object existed in the pool. If the calling thread is interrupted while waiting this call will returnnulland the thread's interrupted status will be set totrue.- Parameters:
timeout- the maximum time to wait for an object to become available in the object pool; this timeout does not include the object creation timeunit- the time unit of thetimeoutargumentwaitedNanos- this parameter is used to report the nanoseconds time waited for an object to become available in the pool, excluding any object creation time; the time waited will be stored at index0of this array; the array must be of size of at least one- Returns:
- an object taken from the object pool or
nullif the specified timeout expires or if it was interrupted while waiting
-
tryTake
T tryTake()Tries to take an object from the object pool if there is one that is immediately available; the object may need to be created as described intryTake(long, TimeUnit, long[]). Returnsnullif no object is available in the pool at the time of the call.- Returns:
- an object from the object pool or
nullif no object was available
-
restore
Restores (returns) an object to the object pool. The object pool does not verify whether the currently restored object has been taken before that from this object pool or whether it is currently in taken state. Equivalent to callingrestore(object, true).- Parameters:
object- the object to be restored / returned- Throws:
NullPointerException- if the given object isnull
-
restore
Restores (returns) an object to the object pool. The object pool does not verify whether the currently restored object has been taken before that from this object pool or whether it is currently in taken state.- Parameters:
object- the object to be restored / returnedvalid- iffalse, the object is treated as invalid; otherwise a secondary validation on the object will be performed- Throws:
NullPointerException- if the given object isnull
-
listener
Returns theListenerinterface instance associated with this object pool, if any.- Returns:
- see above;
nullmeans noListeneris associated with this object pool.
-
isFair
boolean isFair()Returns the fairness setting of this object pool.- Returns:
trueif the object pool is fair to waiting taker threads
-