Interface ElementPool<T>

All Known Implementing Classes:
StringBuilderPool

public interface ElementPool<T>
In an application, you can have resources that are limited or time-consuming to create a new one. A solution is to create a limited resource once and reuse it. The object pool design will have the mechanism to create a bulk of objects to pooling use. If the requirements of resources increases, the current bulk's size will be also automatically increased.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clean up, after that all array elements will be set to null.
    get()
    Retrieves an element in the current pool.
    int
    Retrieves the current available slots.
    int
    Retrieves the pool size.
    void
    repay(T element)
    When you finished using an element, repay (free) it for the reusing.
  • Method Details

    • get

      T get()
      Retrieves an element in the current pool.
      Returns:
      an element in the pool
    • repay

      void repay(T element) throws NullElementPoolException
      When you finished using an element, repay (free) it for the reusing.
      Parameters:
      element - the finished using element
      Throws:
      NullElementPoolException - when you try to repay an invalid element
    • cleanup

      void cleanup()
      Clean up, after that all array elements will be set to null.
    • getPoolSize

      int getPoolSize()
      Retrieves the pool size.
      Returns:
      the total number of element or -1 if any exceptions caused
    • getAvailableSlot

      int getAvailableSlot()
      Retrieves the current available slots.
      Returns:
      the number of available slots in the pool