|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ObjectPool
Allows for reuse of instances without having to constantly instantiate new ones and discard old ones.
Whenever there is a high turn-over rate of certain type of objects, relying on instantiation and
garbage collection can significantly slow down the system. Instantiation is a fairly expensive
process and garbage collection usually doesn't happen until it has to, which means memory gets
eaten away at until the last moment when everything slows down to let GC to kick in.
ObjectPool
works by simply caching instances. Instantiation and preparation
of instances is delegated to an implementation of ObjectGenerator
.
Historically, before this interface was added, users had to explicitly refer to ObjectRecycler
explicitly. A better practice now is to only type your references as ObjectPool
.
ObjectRecycler
Method Summary | |
---|---|
void |
clearCache()
Clears existing cache. |
java.lang.Object |
getObject()
Gets an instance out of the pool with default initialization. |
java.lang.Object |
getObject(java.lang.Object arg)
Gets an instance out of the pool and initializes it using the specified parameter object. |
boolean |
recycleObject(java.lang.Object obj)
Returns an object into the pool. |
Method Detail |
---|
java.lang.Object getObject() throws java.lang.IllegalArgumentException
getObject(null)
.
java.lang.IllegalArgumentException
getObject(java.lang.Object)
java.lang.Object getObject(java.lang.Object arg) throws java.lang.IllegalArgumentException
arg
- Initialization parameter. If null
, default initialziation is used.
java.lang.IllegalArgumentException
boolean recycleObject(java.lang.Object obj)
getObject()
or getObject(arg)
.
getObject()
,
getObject(java.lang.Object)
void clearCache()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |