|
|||||||||
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<ManagedObject>
ManagedObject
- public class ObjectManager<ManagedObject>
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<ManagedObject> objectFactory)
|
|
ObjectManager(IObjectFactory<ManagedObject> objectFactory,
int initialObjectCount)
|
|
ObjectManager(IObjectFactory<ManagedObject> objectFactory,
int initialObjectCount,
int moreNewObjectsCount)
|
Method Summary | |
---|---|
ManagedObject |
get()
Returns you an instance of object. |
void |
giveBack(ManagedObject 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<ManagedObject> objectFactory)
public ObjectManager(IObjectFactory<ManagedObject> objectFactory, int initialObjectCount)
objectFactory
- initialObjectCount
- how many objects to create in advancepublic ObjectManager(IObjectFactory<ManagedObject> 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 ManagedObject get()
public void giveBack(ManagedObject obj)
obj
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |