Wednesday, January 6, 2016

CompletableFuture

Basic usage

// Use runAsync instead when the Task is a Runnable
final CompletableFuture<String> f1 = 

    CompletableFuture.supplyAsync(() -> longRunningTask1(params), executor);
final CompletableFuture<String> f2 = ...

final CompletableFuture<String> f3 = ...

// Wait for all to complete

CompletableFuture.allOf(f1, f2, f3).join();

References:

No comments:

Post a Comment