Java Utililty Methods Thread Future

List of utility methods to do Thread Future

Description

The list of methods to do Thread Future are organized into topic(s).

Method

CompletableFuturewaitForAll(List> futures)
Return a future that represents the completion of the futures in the provided list
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
voidwaitForAll(List> res)
For lists of Future results that we are uninterested in, act as a Barrier and attempt to get all futures.
for (Future<?> f : res)
    try {
        f.get();
    } catch (InterruptedException | ExecutionException e) {
voidwaitForCompletion(Collection> futures)
Blocks and waits for all Futures in the given collection to complete.
for (Future<?> future : futures) {
    try {
        future.get();
    } catch (ExecutionException ex) {
        throw new RuntimeException("Exception during execution", ex);
    } catch (InterruptedException ex) {
        throw new RuntimeException("Thread interrupted", ex);
voidwaitForCompletion(Future[] futures)
Waits for all threads to complete computation.
int size = futures.length;
try {
    for (int j = 0; j < size; j++) {
        futures[j].get();
} catch (ExecutionException ex) {
    ex.printStackTrace();
} catch (InterruptedException e) {
...
intwaitForTasks(List futures)
wait For Tasks
int total = 0;
for (Future future : futures) {
    try {
        future.get();
        total++;
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
futures.clear();
return total;