@InterfaceAudience.Private public class SoftObjectPool<K,V> extends ObjectPool<K,V>
SoftReference
based shared object pool.
The objects are kept in soft references and
associated with keys which are identified by the equals
method.
The objects are created by ObjectFactory on demand.
The object creation is expected to be lightweight,
and the objects may be excessively created and discarded.
Thread safe.ObjectPool.ObjectFactory<K,V>
DEFAULT_CONCURRENCY_LEVEL, DEFAULT_INITIAL_CAPACITY, referenceCache, staleRefQueue
Constructor and Description |
---|
SoftObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory) |
SoftObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory,
int initialCapacity) |
SoftObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory,
int initialCapacity,
int concurrencyLevel) |
Modifier and Type | Method and Description |
---|---|
Reference<V> |
createReference(K key,
V obj)
Create a reference associated with the given object
|
K |
getReferenceKey(Reference<V> ref)
Get key of the given reference
|
get, purge, size
public SoftObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory)
public SoftObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory, int initialCapacity)
public SoftObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory, int initialCapacity, int concurrencyLevel)
public Reference<V> createReference(K key, V obj)
ObjectPool
createReference
in class ObjectPool<K,V>
key
- the key to store in the referenceobj
- the object to associate withpublic K getReferenceKey(Reference<V> ref)
ObjectPool
getReferenceKey
in class ObjectPool<K,V>
ref
- The referenceCopyright © 2007–2019 Cloudera. All rights reserved.