Created
February 10, 2016 00:22
-
-
Save khaosans/57d4663d85016235a514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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