Class Pool<T>

java.lang.Object
net.ssehub.easy.basics.pool.Pool<T>
Type Parameters:
T - the type of instances to be managed

public class Pool<T> extends Object
Implements a simple pool for explicit memory management of frequently created elements. In order to keep interfaces of instances clean, we delegate creation and clear operation to the IPoolManager delegate.
Author:
Holger Eichelberger
  • Field Details

  • Constructor Details

    • Pool

      public Pool(IPoolManager<T> manager)
      Creates a new pool for a given type of instances represented by its pool manager.
      Parameters:
      manager - the pool manager
  • Method Details

    • getInstance

      public T getInstance()
      Returns an instance from the pool or creates a new instance via the manager.
      Returns:
      an instance
    • releaseInstance

      public void releaseInstance(T instance)
      Releases an instance obtained from getInstance().
      Cave: Do not release instances twice!
      Parameters:
      instance - the instance to be released (ignored if null)
    • containsByRef

      private boolean containsByRef(T instance)
      Returns whether the pool already contains instance.
      Parameters:
      instance - the instance to look for (by reference)
      Returns:
      true if the reference is already there, false else