Class PoolContext
- java.lang.Object
-
- javolution37.javolution.realtime.Context
-
- javolution37.javolution.realtime.PoolContext
-
public class PoolContext extends Context
This class represents a pool context; it is used to recycle objects transparently, reduce memory allocation and avoid garbage collection.
Threads executing in a pool context may allocate objects from the context's pools (also called "stack") through an
ObjectFactory. Allocated objects are recycled automatically uponexit. This recycling is almost instantaneous and has no impact on performance.Objects allocated within a pool context should not be directly referenced outside of the context unless they are
exported(e.g. result being returned) orpreserved(e.g. shared static instance). If this simple rule is followed, then pool context are completely safe. In fact, pool contexts promote the use of immutable objects (as their allocation cost is then negligible with no adverse effect on garbarge collection) and often lead to safer, faster and more robust applications.Finally, the framework guarantees that all pool objects belongs to the same memory area (the memory area where the pool context resides). In other words, pool contexts allocated in ImmortalMemory can safely be used by
NoHeapRealtimeThreadexecuting inScopedMemory.
-
-
Constructor Summary
Constructors Constructor and Description PoolContext()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Moves all objects belonging to this pool context to the heap.static PoolContextcurrent()Returns the current pool context ornullif the current thread does not execute within a pool context.static voidenter()Enters aPoolContextallocated in the same memory area as the memory area of the current context.static voidexit()Exits the currentPoolContext.
-
-
-
Method Detail
-
current
public static PoolContext current()
Returns the current pool context ornullif the current thread does not execute within a pool context.- Returns:
- the current pool context.
-
enter
public static void enter()
Enters aPoolContextallocated in the same memory area as the memory area of the current context.
-
exit
public static void exit()
Exits the currentPoolContext.- Throws:
java.lang.IllegalStateException- if the current context is not an instance of PoolContext.
-
-
DMelt 3.0 © DataMelt by jWork.ORG