Package org.restlet.engine.util
Class Pool<T>
java.lang.Object
org.restlet.engine.util.Pool<T>
- Type Parameters:
T-
Generic object pool.
- Author:
- Jerome Louvel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks in an object into the pool.checkout()Checks out an object from the pool.voidclear()Clears the store of reusable objects.protected voidClears the given object when it is checked in the pool.protected abstract TCreates a new reusable object.Creates the store of reusable objects.getStore()Returns the store containing the reusable objects.voidpreCreate(int initialSize) Pre-creates the initial objects using thecreateObject()method and check them in the pool using thecheckin(Object)method.
-
Constructor Details
-
Pool
public Pool()Default constructor. -
Pool
public Pool(int initialSize) Constructor. Pre-creates the minimum number of objects if needed using thepreCreate(int)method.- Parameters:
initialSize- The initial number of objects in the pool.
-
-
Method Details
-
checkin
Checks in an object into the pool.- Parameters:
object- The object to check in.
-
checkout
Checks out an object from the pool. Creates a new one if the pool is empty.- Returns:
- An object from the pool.
-
clear
public void clear()Clears the store of reusable objects. -
clear
Clears the given object when it is checked in the pool. Does nothing by default.- Parameters:
object- The object to clear.
-
createObject
Creates a new reusable object.- Returns:
- A new reusable object.
-
createStore
Creates the store of reusable objects.- Returns:
- The store of reusable objects.
-
getStore
Returns the store containing the reusable objects.- Returns:
- The store containing the reusable objects.
-
preCreate
public void preCreate(int initialSize) Pre-creates the initial objects using thecreateObject()method and check them in the pool using thecheckin(Object)method.- Parameters:
initialSize- The initial number of objects.
-