Class ResourcePool<T>
java.lang.Object
org.apache.hadoop.fs.impl.prefetch.ResourcePool<T>
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
BoundedResourcePool
Manages a fixed pool of resources.
Avoids creating a new resource if a previously created instance is already available.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Tacquire()Acquires a resource blocking if necessary until one becomes available.voidclose()protected voidDerived classes may implement a way to cleanup each item.protected abstract TDerived classes must implement a way to create an instance of a resource.abstract voidReleases a previously acquired resource.abstract TAcquires a resource blocking if one is immediately available.
-
Constructor Details
-
ResourcePool
public ResourcePool()
-
-
Method Details
-
acquire
Acquires a resource blocking if necessary until one becomes available.- Returns:
- the acquired resource instance.
-
tryAcquire
Acquires a resource blocking if one is immediately available. Otherwise returns null.- Returns:
- the acquired resource instance (if immediately available) or null.
-
release
Releases a previously acquired resource.- Parameters:
item- the resource to release.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
close
Derived classes may implement a way to cleanup each item.- Parameters:
item- the resource to close.
-
createNew
Derived classes must implement a way to create an instance of a resource.- Returns:
- the created instance.
-