ResourcePool (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.fs.impl.prefetch, class: ResourcePool

Package org.apache.hadoop.fs.impl.prefetch

# Class ResourcePool<T>

java.lang.Object
org.apache.hadoop.fs.impl.prefetch.ResourcePool<T>

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Direct Known Subclasses:
  `BoundedResourcePool`

public abstract class ResourcePool<T> extends Object implements Closeable
Manages a fixed pool of resources. Avoids creating a new resource if a previously created instance is already available.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ResourcePool()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract T`
  `acquire()`
  Acquires a resource blocking if necessary until one becomes available.
  `void`
  `close()`
  `protected void`
  `close(T item)`
  Derived classes may implement a way to cleanup each item.
  `protected abstract T`
  `createNew()`
  Derived classes must implement a way to create an instance of a resource.
  `abstract void`
  `release(T item)`
  Releases a previously acquired resource.
  `abstract T`
  `tryAcquire()`
  Acquires a resource blocking if one is immediately available.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ResourcePool

    public ResourcePool()

- ## Method Details

  - ### acquire

    public abstract T acquire()
    Acquires a resource blocking if necessary until one becomes available.
    Returns:
      the acquired resource instance.

  - ### tryAcquire

    public abstract T tryAcquire()
    Acquires a resource blocking if one is immediately available. Otherwise returns null.
    Returns:
      the acquired resource instance (if immediately available) or null.

  - ### release

    public abstract void release(T item)
    Releases a previously acquired resource.
    Parameters:
      `item` - the resource to release.

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`

  - ### close

    protected void close(T item)
    Derived classes may implement a way to cleanup each item.
    Parameters:
      `item` - the resource to close.

  - ### createNew

    protected abstract T createNew()
    Derived classes must implement a way to create an instance of a resource.
    Returns:
      the created instance.