Class ExampleObjectPool

java.lang.Object
de.calamanari.pk.objectpool.ExampleObjectPool

public class ExampleObjectPool
extends java.lang.Object
Example Object Pool - demonstrates an OBJECT POOL.
Author:
Karl Eilebrecht
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int MAX_POOL_SIZE
    maximum pool size
  • Constructor Summary

    Constructors
    Constructor Description
    ExampleObjectPool()  
  • Method Summary

    Modifier and Type Method Description
    ExampleReusableObject acquireInstance()
    Acquires a free pooled instance from the pool and returns it.
    The pool will auto-resize until the maximum number of instances is reached.
    void returnInstance​(ExampleReusableObject instance)
    Method for returning an instance to the pool after usage.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • acquireInstance

      Acquires a free pooled instance from the pool and returns it.
      The pool will auto-resize until the maximum number of instances is reached. If the maximum number has already been reached, a call to this method blocks until an instance will be returned.
      The caller is responsible for returning an acquired instance.
      Returns:
      instance of pooled object
    • returnInstance

      public void returnInstance​(ExampleReusableObject instance)
      Method for returning an instance to the pool after usage.
      Parameters:
      instance - idle instance for recycling