Class DomBuildersPool
java.lang.Object
org.openehealth.ipf.commons.xml.DomBuildersPool
Pool for DOM document builders (which are not thread-safe).
Document builders retain their internal parser buffers across DocumentBuilder.reset(), so
builders left idle after a traffic burst keep that memory allocated. The pool is therefore
registered with PoolEvictor, which destroys builders that stay idle; see that class for
the interval and sampling system properties.
- Since:
- 3.5.1
- Author:
- Dmytro Rud
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidrestore(DocumentBuilder documentBuilder) Returns a document builder (previously gained viatake()) to the pool.static DocumentBuildertake()Returns a document builder instance from the pool.static <R> Ruse(Function<DocumentBuilder, R> operation) Takes a document builder object from the pool, uses it to execute the given operation, and returns it to the pool.
-
Field Details
-
POOL_SIZE_PROPERTY
-
-
Method Details
-
take
Returns a document builder instance from the pool.Important: The caller MUST return the builder to the pool using
restore(DocumentBuilder)when finished. Consider usinguse(Function)for automatic resource management.- Returns:
- a document builder instance
-
restore
Returns a document builder (previously gained viatake()) to the pool. This method MUST be called as soon as the use of the document builder is finished.- Parameters:
documentBuilder- document builder,nullvalues are safe.
-
use
Takes a document builder object from the pool, uses it to execute the given operation, and returns it to the pool.This is the recommended way to use document builders as it ensures proper resource cleanup.
- Type Parameters:
R- operation return type- Parameters:
operation- operation to execute using a document builder- Returns:
- result of the execution of the operation
- Throws:
RuntimeException- if the operation throws an exception
-