java.lang.Object
net.sansa_stack.query.spark.ontop.kryo.Pool<T>

public abstract class Pool<T> extends Object
A pool of objects that can be reused to avoid allocations. The pool is optionally thread safe and can be configured to use soft references.
Author:
Nathan Sweet, Martin Grotzke
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Objects implementing this interface will have Pool.Poolable.reset() called when passed to free(Object).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pool(boolean threadSafe, boolean softReferences)
    Creates a pool with no maximum.
    Pool(boolean threadSafe, boolean softReferences, int maximumCapacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    If using soft references, all soft references whose objects have been garbage collected are removed from the pool.
    void
    Removes all free objects from this pool.
    protected abstract T
     
    void
    free(T object)
    Puts the specified object in the pool, making it eligible to be returned by obtain().
    int
    The number of objects available to be obtained.
    int
    The all-time highest number of free objects.
    Returns an object from this pool.
    protected void
    reset(T object)
    Called when an object is freed to clear the state of the object for possible later reuse.
    void
     

    Methods inherited from class java.lang.Object

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

    • Pool

      public Pool(boolean threadSafe, boolean softReferences)
      Creates a pool with no maximum.
    • Pool

      public Pool(boolean threadSafe, boolean softReferences, int maximumCapacity)
      Parameters:
      maximumCapacity - The maximum number of free objects to store in this pool. Objects are not created until obtain() is called and no free objects are available.
  • Method Details

    • create

      protected abstract T create()
    • obtain

      public T obtain()
      Returns an object from this pool. The object may be new (from create()) or reused (previously freed).
    • free

      public void free(T object)
      Puts the specified object in the pool, making it eligible to be returned by obtain(). If the pool already contains the maximum number of free objects, the specified object is reset but not added to the pool.

      If using soft references and the pool contains the maximum number of free objects, the first soft reference whose object has been garbage collected is discarded to make room.

    • reset

      protected void reset(T object)
      Called when an object is freed to clear the state of the object for possible later reuse. The default implementation calls Pool.Poolable.reset() if the object is Pool.Poolable.
    • clear

      public void clear()
      Removes all free objects from this pool.
    • clean

      public void clean()
      If using soft references, all soft references whose objects have been garbage collected are removed from the pool. This can be useful to reduce the number of objects in the pool before calling getFree() or when the pool has no maximum capacity. It is not necessary to call clean() before calling free(Object), which will try to remove an empty reference if the maximum capacity has been reached.
    • getFree

      public int getFree()
      The number of objects available to be obtained.

      If using soft references, this number may include objects that have been garbage collected. clean() may be used first to remove empty soft references.

    • getPeak

      public int getPeak()
      The all-time highest number of free objects. This can help determine if a pool's maximum capacity is set appropriately. It can be reset any time with resetPeak().

      If using soft references, this number may include objects that have been garbage collected.

    • resetPeak

      public void resetPeak()