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

Class 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 upon exit. 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) or preserved (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 NoHeapRealtimeThread executing in ScopedMemory.

    • 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
      void clear()
      Moves all objects belonging to this pool context to the heap.
      static PoolContext current()
      Returns the current pool context or null if the current thread does not execute within a pool context.
      static void enter()
      Enters a PoolContext allocated in the same memory area as the memory area of the current context.
      static void exit()
      Exits the current PoolContext.
      • Methods inherited from class java.lang.Object

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

      • PoolContext

        public PoolContext()
        Default constructor.
    • Method Detail

      • current

        public static PoolContext current()
        Returns the current pool context or null if the current thread does not execute within a pool context.
        Returns:
        the current pool context.
      • enter

        public static void enter()
        Enters a PoolContext allocated in the same memory area as the memory area of the current context.
      • exit

        public static void exit()
        Exits the current PoolContext.
        Throws:
        java.lang.IllegalStateException - if the current context is not an instance of PoolContext.
      • clear

        public void clear()
        Moves all objects belonging to this pool context to the heap.
        Overrides:
        clear in class Context

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.