Class SimpleObjectsPool

  • All Implemented Interfaces:

    
    public final class SimpleObjectsPool<T extends Object>
    
                        

    Normally it's ok to create short-lived objects and let GC take care of them. However, sometimes we have strict requirements for application latency (the case in high frequency electronic trading).

    In this situation it might be desirable to have a pool of objects and reuse them to avoid memory consumption, thus reducing GC impact.

    That design goes great with disruptor pattern when new task in enqueued to a worker thread in a thread-safe manner and all further processing is thread-local (lock-free).

    This class is a simple objects pool.

    Note: this class is not thread-safe.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final T next
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleObjectsPool(Function0<T> initializer, Function1<T, Unit> resetter)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final T getNext()
      final Unit restore(T item)
      • Methods inherited from class java.lang.Object

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

      • SimpleObjectsPool

        SimpleObjectsPool(Function0<T> initializer, Function1<T, Unit> resetter)