Class FixedInstancePool<T>

java.lang.Object
com.univocity.parsers.common.input.concurrent.FixedInstancePool<T>
Type Parameters:
T - the class of objects stored in the instance pool

abstract class FixedInstancePool<T> extends Object
A very simple object instance pool with a fixed size.

This is essentially an immutable circular queue. Elements are not added nor removed. Pointers to the head and tail of the queue identify what is the next available entry.

Use allocate() to get an available Entry from the pool. If all objects are allocated then the thread will block until an element is released.

release(Entry) releases an allocated Entry for reuse.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) int
     
    private int
     
    private final int[]
     
    (package private) final Entry<T>[]
     
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance pool with the given size.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the next available entry in this instance pool.
    protected abstract T
    Creates a new instance of the given type of objects stored as entries of this instance pool This method is called in the constructor of this class for initialization of the instance array and must always return a new instance.
    void
    Releases the given entry and makes it available for allocation (by allocate())

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • instancePool

      final Entry<T>[] instancePool
    • instanceIndexes

      private final int[] instanceIndexes
    • tail

      private int tail
    • count

      int count
    • lastInstanceIndex

      private int lastInstanceIndex
  • Constructor Details

    • FixedInstancePool

      FixedInstancePool(int size)
      Creates a new instance pool with the given size. Upon instantiation, the newInstance() method will be called to fill in the instance pool, and the pool can then have its entries allocated for use (and reuse).
      Parameters:
      size - the size of the fixed instance pool.
  • Method Details

    • newInstance

      protected abstract T newInstance()
      Creates a new instance of the given type of objects stored as entries of this instance pool This method is called in the constructor of this class for initialization of the instance array and must always return a new instance.
      Returns:
      returns a new instance to use in the pool
    • allocate

      public Entry<T> allocate()
      Retrieves the next available entry in this instance pool. Blocks until an entry becomes available (through release(Entry)).
      Returns:
      the next available entry in this instance pool
    • release

      public void release(Entry<T> e)
      Releases the given entry and makes it available for allocation (by allocate())
      Parameters:
      e - the entry to be released and made available for reuse.