Class ObjectPool<T>

java.lang.Object
io.opentelemetry.sdk.metrics.internal.state.ObjectPool<T>

public final class ObjectPool<T> extends Object
A pool of objects of type T.

When an object is borrowed from an empty pool, an object will be created by the supplied objectCreator and returned immediately. When the pool is not empty, an object is removed from the pool and returned. The user is expected to return the object to the pool when it is no longer used.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

This class is not thread-safe.

  • Field Details

  • Constructor Details

    • ObjectPool

      public ObjectPool(Supplier<T> objectCreator)
      Constructs an object pool.
      Parameters:
      objectCreator - Supplier used to create an object when the pool is empty
  • Method Details

    • borrowObject

      public T borrowObject()
      Gets an object from the pool.
      Returns:
      An object from the pool, or a new object if the pool is empty
    • returnObject

      public void returnObject(T object)