Class ObjectPool<K,V>

java.lang.Object
org.apache.hadoop.hbase.util.ObjectPool<K,V>
Direct Known Subclasses:
SoftObjectPool, WeakObjectPool

@Private public abstract class ObjectPool<K,V> extends Object
A thread-safe shared object pool in which object creation is expected to be lightweight, and the objects may be excessively created and discarded.
  • Field Details

  • Constructor Details

    • ObjectPool

      public ObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory)
      Creates a new pool with the default initial capacity (16) and the default concurrency level (16).
      Parameters:
      objectFactory - the factory to supply new objects on demand
      Throws:
      NullPointerException - if objectFactory is null
    • ObjectPool

      public ObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory, int initialCapacity)
      Creates a new pool with the given initial capacity and the default concurrency level (16).
      Parameters:
      objectFactory - the factory to supply new objects on demand
      initialCapacity - the initial capacity to keep objects in the pool
      Throws:
      NullPointerException - if objectFactory is null
      IllegalArgumentException - if initialCapacity is negative
    • ObjectPool

      public ObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory, int initialCapacity, int concurrencyLevel)
      Creates a new pool with the given initial capacity and the given concurrency level.
      Parameters:
      objectFactory - the factory to supply new objects on demand
      initialCapacity - the initial capacity to keep objects in the pool
      concurrencyLevel - the estimated count of concurrently accessing threads
      Throws:
      NullPointerException - if objectFactory is null
      IllegalArgumentException - if initialCapacity is negative or concurrencyLevel is non-positive
  • Method Details

    • purge

      public void purge()
      Removes stale references of shared objects from the pool. References newly becoming stale may still remain.

      The implementation of this method is expected to be lightweight when there is no stale reference with the Oracle (Sun) implementation of ReferenceQueue, because ReferenceQueue.poll just checks a volatile instance variable in ReferenceQueue.

    • createReference

      public abstract Reference<V> createReference(K key, V obj)
      Create a reference associated with the given object
      Parameters:
      key - the key to store in the reference
      obj - the object to associate with
      Returns:
      the reference instance
    • getReferenceKey

      public abstract K getReferenceKey(Reference<V> ref)
      Get key of the given reference
      Parameters:
      ref - The reference
      Returns:
      key of the reference
    • get

      public V get(K key)
      Returns a shared object associated with the given key, which is identified by the equals method.
      Throws:
      NullPointerException - if key is null
    • size

      public int size()
      Returns an estimated count of objects kept in the pool. This also counts stale references, and you might want to call purge() beforehand.