Class DomBuildersPool

java.lang.Object
org.openehealth.ipf.commons.xml.DomBuildersPool

public final class DomBuildersPool extends Object
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 Details

    • POOL_SIZE_PROPERTY

      public static final String POOL_SIZE_PROPERTY
  • Method Details

    • take

      public static DocumentBuilder 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 using use(Function) for automatic resource management.

      Returns:
      a document builder instance
    • restore

      public static void restore(DocumentBuilder documentBuilder)
      Returns a document builder (previously gained via take()) to the pool. This method MUST be called as soon as the use of the document builder is finished.
      Parameters:
      documentBuilder - document builder, null values are safe.
    • use

      public static <R> R use(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.

      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