Class PhasingExecutor

java.lang.Object
org.apache.maven.internal.impl.util.PhasingExecutor
All Implemented Interfaces:
AutoCloseable, Executor

public class PhasingExecutor extends Object implements Executor, AutoCloseable
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