Documentation of 'javolution37.javolution.realtime.ObjectFactory' Java class
ObjectFactory
javolution37.javolution.realtime

Class ObjectFactory<T>

  • Direct Known Subclasses:
    RealtimeObject.Factory


    public abstract class ObjectFactory<T>
    extends java.lang.Object

    This 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.
         

    ObjectFactory instances 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 the heapPool() when the current thread executes in a HeapContext.
      ObjectPool<T> heapPool()
      Returns the pool representing the heap; this pool always returns objects allocated on the heap.
      T object()
      Returns a factory object possibly recycled or preallocated.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • object

        public T object()
        Returns a factory object possibly recycled or preallocated. This method is equivalent to object(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 the heapPool() when the current thread executes in a HeapContext.
        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

You see the box below because you did not login.