Stopping a thread in java CompletableFuture after timeout
问题 I have an async chain in my java code that i want to stop after a certain timeout so i created a threadPool with some threads and called the CompletableFuture like this ExecutorService pool = Executors.newFixedThreadPool(10); than i have a cyclic method that loads data from the db and executes some task on it, once all the CompletableFutures are completed its doing it again CompletableFuture<MyObject> futureTask = CompletableFuture.supplyAsync(() -> candidate, pool) .thenApply(Task1::doWork)