Class PhasingExecutor
java.lang.Object
org.apache.maven.internal.impl.util.PhasingExecutor
- All Implemented Interfaces:
AutoCloseable,Executor
The phasing executor allows executing tasks in parallel and waiting for all tasks
to be executed before fully closing the executor. Tasks can be submitted even after
the close method has been called, allowing for use with try-with-resources.
The
phase() method can be used to submit tasks and wait for them to be
executed without closing the executor.
Example usage:
try (PhasingExecutor executor = createExecutor()) {
try (var phase = executor.phase()) {
executor.execute(() -> { /* task 1 */ });
executor.execute(() -> { /* task 2 */ });
More tasks...
} This will wait for all tasks in this phase to complete
You can have multiple phases
try (var anotherPhase = executor.phase()) {
executor.execute(() -> { /* another task */ });
}
} The executor will wait for all tasks to complete before shutting down
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprivate final AtomicIntegerprivate final ExecutorServiceprivate final intprivate static final AtomicIntegerprivate final AtomicBooleanprivate final ReentrantLockprivate static final org.slf4j.Loggerprivate final AtomicBooleanprivate final Condition -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
ID
-
LOGGER
private static final org.slf4j.Logger LOGGER -
executor
-
shutdownInitiated
-
inPhase
-
activeTaskCount
-
completedTaskCount
-
id
private final int id -
lock
-
taskCompletionCondition
-
-
Constructor Details
-
PhasingExecutor
-
-
Method Details
-
execute
-
phase
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
log
-
log
-
log
-