Class ParallelValidationConfig

java.lang.Object
dev.metaschema.core.model.constraint.ParallelValidationConfig
All Implemented Interfaces:
AutoCloseable

public final class ParallelValidationConfig extends Object implements AutoCloseable
Configuration for parallel constraint validation.

This class supports two modes:

Instances should be used with try-with-resources or explicitly closed after validation.

  • Field Details

    • SEQUENTIAL

      @NonNull public static final ParallelValidationConfig SEQUENTIAL
      Single-threaded sequential execution (default, current behavior).

      This instance does not need to be closed.

  • Method Details

    • withExecutor

      @NonNull @Owning public static @Owning ParallelValidationConfig withExecutor(@NonNull ExecutorService executor)
      Create configuration using an application-provided executor.

      The executor is NOT shut down by close(); the caller retains ownership.

      The caller owns the returned configuration and is responsible for closing it.

      Parameters:
      executor - the executor service to use for parallel tasks
      Returns:
      configuration using the provided executor
      Throws:
      NullPointerException - if executor is null
    • withThreads

      @NonNull @Owning public static @Owning ParallelValidationConfig withThreads(int threadCount)
      Create configuration that creates an internal thread pool.

      The internal pool is shut down when close() is called.

      The caller owns the returned configuration and is responsible for closing it.

      Parameters:
      threadCount - number of threads (must be >= 1)
      Returns:
      configuration with internal thread pool
      Throws:
      IllegalArgumentException - if threadCount < 1
    • isParallel

      public boolean isParallel()
      Check if parallel execution is enabled.
      Returns:
      true if using more than one thread
    • getExecutor

      @NonNull public ExecutorService getExecutor()
      Get the executor service, creating an internal pool if needed.

      For internal pools, the executor is created lazily on first call.

      Returns:
      the executor service
      Throws:
      IllegalStateException - if called on SEQUENTIAL config
    • close

      public void close()
      Shut down internal executor if one was created.

      Does nothing if using an external executor or if no executor was created.

      Specified by:
      close in interface AutoCloseable