Module dev.metaschema.core
Class ParallelValidationConfig
java.lang.Object
dev.metaschema.core.model.constraint.ParallelValidationConfig
- All Implemented Interfaces:
AutoCloseable
Configuration for parallel constraint validation.
This class supports two modes:
- Internal thread pool: Created via
withThreads(int), shut down byclose(). UsesForkJoinPoolinternally to handle nested parallelism without deadlock. - External executor: Provided via
withExecutor(ExecutorService), NOT shut down byclose()
Instances should be used with try-with-resources or explicitly closed after validation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ParallelValidationConfigSingle-threaded sequential execution (default, current behavior). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shut down internal executor if one was created.Get the executor service, creating an internal pool if needed.booleanCheck if parallel execution is enabled.static @Owning ParallelValidationConfigwithExecutor(ExecutorService executor) Create configuration using an application-provided executor.static @Owning ParallelValidationConfigwithThreads(int threadCount) Create configuration that creates an internal thread pool.
-
Field Details
-
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
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
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:
closein interfaceAutoCloseable
-