Class ObjectFactory<T>
- java.lang.Object
-
- javolution37.javolution.realtime.ObjectFactory<T>
-
- Direct Known Subclasses:
- RealtimeObject.Factory
public abstract class ObjectFactory<T> extends java.lang.ObjectThis class represents an object factory; it allows for object recycling and pre-allocation.
Object factories are recommended over class constructors (ref. "new" keyword) in order to benefit from context-based allocation policies. For example:
static ObjectFactory<int[][]> BOARD_FACTORY = new ObjectFactory<int[][]>() { protected int[][] create() { return new int[8][8]; } }; ... int[][] board = BOARD_FACTORY.object(); // On the stack if current thread executes ... // in a PoolContext; heap otherwise.ObjectFactoryinstances are uniquely identified by their class (one instance per sub-class). The number of instances is voluntarely limited (see Javolution Configuration for details).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ObjectPool<T>currentPool()Returns the local pool for the current thread or theheapPool()when the current thread executes in aHeapContext.ObjectPool<T>heapPool()Returns the pool representing the heap; this pool always returns objects allocated on the heap.Tobject()Returns a factory object possibly recycled or preallocated.
-
-
-
Method Detail
-
object
public T object()
Returns a factory object possibly recycled or preallocated. This method is equivalent toobject(PoolContext.current()).- Returns:
- a recycled, pre-allocated or new factory object.
-
currentPool
public final ObjectPool<T> currentPool()
Returns the local pool for the current thread or theheapPool()when the current thread executes in aHeapContext.- Returns:
- the local pool or a pool representing the heap.
-
heapPool
public final ObjectPool<T> heapPool()
Returns the pool representing the heap; this pool always returns objects allocated on the heap.- Returns:
- the heap pool for this factory.
-
-
DMelt 3.0 © DataMelt by jWork.ORG