CompletableFuture get result without blocking

private static boolean validateSMTP(final ArrayList mxList, String address) throws ExecutionException, InterruptedException {

ExecutorService pool = Executors.newFixedThreadPool(mxList.size());

List> allVerifiers = new ArrayList<>();

for (int mx = 0; mx < mxList.size(); mx++) {

CompletableFuture verifier = createAsyncVerifier((String) mxList.get(mx), address, pool);

verifier.thenApply(isvalid -> isvalid);

verifier.get();

}

return false;

}

In above code i want to create mxList.size() CompletableFuture , execute each and if the result of any of them is true i want to break the loop , when i used get() method it blocks and i waste the benefit of concurrency , any idea about how to do that ?...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts