CompletableFuture with timeout

Two CompletableFutures ┬ácan be combined to timeout the CompletableFuture with the business logic like below: ┬ápackage competablefuture; import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class CompletableFutureSample { static ScheduledExecutorService pool = Executors.newScheduledThreadPool(4); public static CompletableFuture executeAsyncTimed(Duration duration) { final CompletableFuture asyncTimedFuture = new CompletableFuture<>(); pool.schedule(() -> asyncTimedFuture.completeExceptionally(new TimeoutException()), duration.toMillis(), … More CompletableFuture with timeout