Skip to content

Instantly share code, notes, and snippets.

@khaosans
Created February 10, 2016 00:22
Show Gist options
  • Save khaosans/57d4663d85016235a514 to your computer and use it in GitHub Desktop.
Save khaosans/57d4663d85016235a514 to your computer and use it in GitHub Desktop.
package com.concretepage.util.concurrent;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class CompletableFutureOneExample {
public static void main(String[] args) throws InterruptedException {
List<Integer> list = Arrays.asList(10,20,30,40);
list.stream().map(data->CompletableFuture.supplyAsync(()->getNumber(data))).
map(compFuture->compFuture.thenApply(n->n*n)).map(t->t.join())
.forEach(s->System.out.println(s));
}
private static int getNumber(int a){
return a*a;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment