|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.utils.objectmanager.ObjectManager<MANAGED_OBJECT>
MANAGED_OBJECT
- public class ObjectManager<MANAGED_OBJECT>
ObjectManager is a class that helps you to keep unused objects in the memory. Rather then to create the objects again and again you can retrieve their old instances. Of course those objects must be reusable and have support for resetting it's crucial variables to your liking.
Implementation is using soft references therefore you don't have to worry about memory leakage - if JVM will need more memory it will purge those soft references.
Note that the manager is thread-safe + get() will always return you an old (or possibly) new instance of the object.
We discourage you to use ObjectManager for objects that have multiple references throughout your code as it is hard to know whether the object is not referenced from other parts of your code so you can give it back to the manager.
Constructor Summary | |
---|---|
ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory)
|
|
ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory,
int initialObjectCount)
|
|
ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory,
int initialObjectCount,
int moreNewObjectsCount)
|
Method Summary | |
---|---|
MANAGED_OBJECT |
get()
Returns you an instance of object. |
void |
giveBack(MANAGED_OBJECT obj)
Returns an instance of object to the manager, it will be stored in the manager via soft reference. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory)
public ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory, int initialObjectCount)
objectFactory
- initialObjectCount
- how many objects to create in advancepublic ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory, int initialObjectCount, int moreNewObjectsCount)
objectFactory
- initialObjectCount
- how many objects to create in advancemoreNewObjectsCount
- how many new objects to create in advance in case of shortage of free objectsMethod Detail |
---|
public MANAGED_OBJECT get()
public void giveBack(MANAGED_OBJECT obj)
obj
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |