|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.cosylab.util.ObjectPool
public class ObjectPool
A simple object pool. This pool is created with an initial capacity and a class
(must be a subclass of PoolableObject
) of the objects it contains.
The pool contains at most capacity
of resurrected objects, which it
clears (by invoking PoolableObject.clear
) before returning them to the
user. The user can request a new instance. If found in the pool, it is cleared and
returned. Otherwise a new instance creation is attempted with the default constructor.
If it fails, null
is returned.
Constructor Summary | |
---|---|
ObjectPool(java.lang.Class objectType,
int capacity)
Creates a new object pool with an initial capacity and the type of the pooled objects. |
|
ObjectPool(ObjectFactory objectFactory,
int capacity)
Creates a new object pool with an initial capacity and ObjectFactory for creating new instances of pooled objects. |
Method Summary | |
---|---|
static void |
main(java.lang.String[] args)
Contains a test sample implementation of a poolable object and the use of thread pool. |
PoolableObject |
newInstance()
Produces a new instance. |
void |
returnToPool(PoolableObject p)
Must be invoked from the finalize method of the
PoolableObject s to return them to the object pool. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectPool(java.lang.Class objectType, int capacity)
objectType
- a type descending from PoolableObject
capacity
- the initial capacity of the object poolpublic ObjectPool(ObjectFactory objectFactory, int capacity)
objectFactory
- ObjectFactory for creating new instances of pooled objectscapacity
- the initial capacity of the object poolMethod Detail |
---|
public PoolableObject newInstance()
ObjectFactory
null
if the new type construction failedpublic void returnToPool(PoolableObject p)
finalize
method of the
PoolableObject
s to return them to the object pool.
This method will add the object to the pool if there is any room
left, otherwise the reference and the object will be discarded.
p
- the object being returned to the poolpublic static void main(java.lang.String[] args)
args
- ignored.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |