Skip to content

Instantly share code, notes, and snippets.

@nkcoder
Created December 21, 2016 14:30
Show Gist options
  • Save nkcoder/fbdfba17b6310112fef9b07fa6d1dc49 to your computer and use it in GitHub Desktop.
Save nkcoder/fbdfba17b6310112fef9b07fa6d1dc49 to your computer and use it in GitHub Desktop.
CompletableFuture Test
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