@InterfaceAudience.Private public class WeakObjectPool<K,V> extends ObjectPool<K,V>
WeakReference based shared object pool.
The objects are kept in weak references and
associated with keys which are identified by the equals method.
The objects are created by ObjectPool.ObjectFactory on
demand. The object creation is expected to be lightweight, and the objects may be excessively
created and discarded.
Thread safe.| Modifier and Type | Class and Description |
|---|---|
private class |
WeakObjectPool.WeakObjectReference |
ObjectPool.ObjectFactory<K,V>DEFAULT_CONCURRENCY_LEVEL, DEFAULT_INITIAL_CAPACITY, referenceCache, staleRefQueue| Constructor and Description |
|---|
WeakObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory) |
WeakObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory,
int initialCapacity) |
WeakObjectPool(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, sizepublic WeakObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory)
public WeakObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory, int initialCapacity)
public WeakObjectPool(ObjectPool.ObjectFactory<K,V> objectFactory, int initialCapacity, int concurrencyLevel)
public Reference<V> createReference(K key, V obj)
ObjectPoolcreateReference in class ObjectPool<K,V>key - the key to store in the referenceobj - the object to associate withpublic K getReferenceKey(Reference<V> ref)
ObjectPoolgetReferenceKey in class ObjectPool<K,V>ref - The referenceCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.