T - is the type of the object this pool will contain.
One important thing to understand that this pool will not create any instance of the object.
Rather it will only save them and return them when requested.public class Pool<T extends Reusable> extends Object
| Constructor and Description |
|---|
Pool()
Default constructor.
|
Pool(Class<T> objectClass)
Constructor will set the max pool size to
DEFAULT_MAX_POOL_SIZE |
Pool(Class<T> objectClass,
int maxPoolSize)
Create a pool with given maximum pool size.
|
Pool(int maxPoolSize)
Constructor with maximum pool size.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getInstanceCreated() |
int |
getInstanceNotSavedCount()
Return the count for which instance was supposed to be saved for reuse, but it didn't because of
maxPoolSize restriction. |
T |
getNewObject()
Get an object from the pool if available.
|
void |
returnToPool(T object)
When an object has been used and dusted, then must be return to pool so that later it can be reused.
|
int |
size()
Return the current size of this pool.
|
public Pool()
public Pool(Class<T> objectClass)
DEFAULT_MAX_POOL_SIZEobjectClass - This value is mainly used to create a new instance if no free instance is found. this value
can be null, then calling getNewObject() will return null if no free instance is found
If this value is not null, then getNewObject() will try to create a new instance
of this class and return in case no free instance is found.public Pool(int maxPoolSize)
maxPoolSize - Maximum size of the pool, that will can be stored in the memory. If pool size exceeds this
limit, then call returnToPool(Reusable) will not save the instance.public Pool(Class<T> objectClass, int maxPoolSize)
maxPoolSize - Maximum size of the pool, that will can be stored in the memory. If pool size exceeds this
limit, then call returnToPool(Reusable) will not save the instance.objectClass - This value is mainly used to create a new instance if no free instance is found. this value
can be null, then calling getNewObject() will return null if no free instance is found
If this value is not null, then getNewObject() will try to create a new instance
of this class and return in case no free instance is found.public int size()
public int getInstanceCreated()
T created from getNewObject()public int getInstanceNotSavedCount()
maxPoolSize restriction.maxPoolSize restriction.public void returnToPool(T object)
object - Object to be returned to the pool. If this object is not null, then Reusable.reset()
method of this object will be called before putting it to free list.public T getNewObject()
objectClass is set properly. Otherwise, null object
will be returned.Copyright © 2023. All rights reserved.