Package net.cnri.util.javascript.nashorn
Class BoundedObjectPool<T>
- java.lang.Object
-
- net.cnri.util.javascript.nashorn.BoundedObjectPool<T>
-
public abstract class BoundedObjectPool<T> extends java.lang.ObjectPool of objects bounded by size where threads may create new objects whenever the pool is empty. Use by subclassing and definingcreate(),reset(Object), anddestroy(Object).
-
-
Constructor Summary
Constructors Constructor Description BoundedObjectPool()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all objects from the pool, callingdestroy(Object)on each.protected abstract Tcreate()Creates a new object if the pool is empty.protected abstract voiddestroy(T obj)Called on an object which will not be returned to the pool.intgetMaxPoolSize()Returns the maximum pool size, 100 by default.Tobtain()Obtains a new object from the pool.voidrecycle(T obj)Returns an object to the pool.protected abstract booleanreset(T obj)Called on an object before it is returned to the pool.voidsetMaxPoolSize(int maxPoolSize)Sets the maximum pool size.
-
-
-
Method Detail
-
getMaxPoolSize
public int getMaxPoolSize()
Returns the maximum pool size, 100 by default.- Returns:
- the maximum pool size, 100 by default.
-
setMaxPoolSize
public void setMaxPoolSize(int maxPoolSize)
Sets the maximum pool size.- Parameters:
maxPoolSize- the new maximum pool size
-
create
protected abstract T create()
Creates a new object if the pool is empty. Implemented by subclasses.- Returns:
- a new object.
-
reset
protected abstract boolean reset(T obj)
Called on an object before it is returned to the pool. Implemented by subclasses.- Parameters:
obj- an object to be reset before returning to the pool.- Returns:
- whether the object can be returned; if false
destroy(Object)will be called.
-
destroy
protected abstract void destroy(T obj)
Called on an object which will not be returned to the pool. Implemented by subclasses.- Parameters:
obj- an object which will not be returned to the pool.
-
clear
public void clear()
Removes all objects from the pool, callingdestroy(Object)on each.
-
obtain
public T obtain()
Obtains a new object from the pool. Callscreate()to create a new object if the pool is empty.- Returns:
- a new object from the pool, or else a newly-created object.
-
recycle
public void recycle(T obj)
Returns an object to the pool. Callsreset(Object)before returning the object. If returning the object might cause the pool size to exceed its maximum, the object is not returned to the pool;reset(Object)is not called, anddestroy(Object)is called.- Parameters:
obj- an object to return to the pool
-
-