Skip to content

Commit 6cc2d1f

Browse files
committed
CompletableFuture example
1 parent e3fa0dd commit 6cc2d1f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.winterbe.java8.samples.concurrent;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
import java.util.concurrent.ExecutionException;
5+
6+
/**
7+
* @author Benjamin Winterberg
8+
*/
9+
public class CompletableFuture1 {
10+
11+
public static void main(String[] args) throws ExecutionException, InterruptedException {
12+
CompletableFuture<String> future = new CompletableFuture<>();
13+
14+
future.complete("42");
15+
16+
future
17+
.thenAccept(System.out::println)
18+
.thenAccept(v -> System.out.println("done"));
19+
20+
}
21+
22+
}

0 commit comments

Comments
 (0)