Tag Archives: wait

Java – Wait for Multiple Processes

In Java, the function Process.onExit() creates a CompletableFuture as exit handler and this is the enabling feature in Java to wait for any termination of a set of processes.

public Process anyProcTermination(List<Process> procs)  {
CompletableFuture<Process>[] exitHandlers =
.map(p -> p.onExit())
CompletableFuture<Object> exitHandle = CompletableFuture.anyOf(exitHandlers);
return (Process) exitHandle.join();