Package rx.internal.util
Class ObjectPool<T>
java.lang.Object
rx.internal.util.ObjectPool<T>
- All Implemented Interfaces:
SchedulerLifecycle
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final int
(package private) final int
private final AtomicReference
<Future<?>> private final long
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ObjectPool
(int min, int max, long validationInterval) Creates the pool. -
Method Summary
Modifier and TypeMethodDescriptionGets the next free object from the pool.protected abstract T
Creates a new object.private void
initialize
(int min) void
returnObject
(T object) Returns object back to the pool.void
shutdown()
Shutdown this pool.void
start()
Allows the Scheduler instance to start threads and accept tasks on them.
-
Field Details
-
pool
-
minSize
final int minSize -
maxSize
final int maxSize -
validationInterval
private final long validationInterval -
periodicTask
-
-
Constructor Details
-
ObjectPool
public ObjectPool() -
ObjectPool
private ObjectPool(int min, int max, long validationInterval) Creates the pool.- Parameters:
validationInterval
- time in seconds for periodical checking of minIdle / maxIdle conditions in a separate thread. When the number of objects is less than minIdle, missing instances will be created. When the number of objects is greater than maxIdle, too many instances will be removed.minIdle
- minimum number of objects residing in the poolmaxIdle
- maximum number of objects residing in the pool
-
-
Method Details
-
borrowObject
Gets the next free object from the pool. If the pool doesn't contain any objects, a new object will be created and given to the caller of this method back.- Returns:
- T borrowed object
-
returnObject
Returns object back to the pool.- Parameters:
object
- object to be returned
-
shutdown
public void shutdown()Shutdown this pool.- Specified by:
shutdown
in interfaceSchedulerLifecycle
-
start
public void start()Description copied from interface:SchedulerLifecycle
Allows the Scheduler instance to start threads and accept tasks on them.Implementations should make sure the call is idempotent and threadsafe.
- Specified by:
start
in interfaceSchedulerLifecycle
-
createObject
Creates a new object.- Returns:
- T new object
-
initialize
private void initialize(int min)
-