Class WeakObjectPool<T,E extends Throwable>
java.lang.Object
org.docx4j.org.apache.xml.security.utils.WeakObjectPool<T,E>
- Direct Known Subclasses:
XMLUtils.DocumentBuilderPool
Abstract base class for pooling objects. The two public methods are
getObject() and (repool(Object). Objects are held through
weak references so even objects that are not repooled are subject to garbage collection.
Subclasses must implement the abstract createObject().
Internally, the pool is stored in a java.util.concurrent.LinkedBlockingDeque instance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockingQueue<WeakReference<T>>created, available objects to be checked out to clientsprivate static final IntegerSynchronized, identity map of loaned out objects (WeakHashMap); use to ensure we repool only object originating from here and do it once. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract TCalled whenever a new pool object is desired; subclasses must implement.Subclasses can subclass to return a more specific type.booleanAdds the given object to the pool, provided that the object was created by this pool.
-
Field Details
-
MARKER_VALUE
-
available
created, available objects to be checked out to clients -
onLoan
Synchronized, identity map of loaned out objects (WeakHashMap); use to ensure we repool only object originating from here and do it once.
-
-
Constructor Details
-
WeakObjectPool
protected WeakObjectPool()The lone constructor.
-
-
Method Details
-
createObject
Called whenever a new pool object is desired; subclasses must implement. -
getObject
Subclasses can subclass to return a more specific type.- Returns:
- an object from the pool; will block until an object is available
- Throws:
E
-
repool
Adds the given object to the pool, provided that the object was created by this pool.- Parameters:
obj- the object to return to the pool- Returns:
- whether the object was successfully added as available
-