Created
December 21, 2016 14:30
-
-
Save nkcoder/fbdfba17b6310112fef9b07fa6d1dc49 to your computer and use it in GitHub Desktop.
CompletableFuture Test
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 org.nkcoder.module.javatest.concurrent; | |
import java.util.concurrent.CompletableFuture; | |
/** | |
* {@link: http://www.deadcoderising.com/java8-writing-asynchronous-code-with-completablefuture/} | |
* Created by nkcoder on 12/21/16. | |
*/ | |
public class CompletableFutureTest { | |
public static void main(String[] args) { | |
int size = 10; | |
for (int i = 1; i <= size; i ++) { | |
final int raw = i; | |
CompletableFuture future = CompletableFuture.supplyAsync(() -> { | |
System.out.println("raw: " + raw); | |
final int multiple = Math.multiplyExact(raw, raw); | |
return multiple; | |
}).thenAccept(in -> System.out.println("multiple: " + in)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment