Skip to content

Commit 078efb8

Browse files
feat
1 parent c67863b commit 078efb8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.concurrent.*;
2+
3+
/**
4+
* @Author: zzStar
5+
* @Date: 09-07-2021 22:23
6+
*/
7+
public class CompletableFutureUsage {
8+
9+
public static void main(String[] args) throws ExecutionException, InterruptedException {
10+
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 20, 1L, TimeUnit.MINUTES,
11+
new LinkedBlockingDeque<>());
12+
13+
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
14+
try {
15+
TimeUnit.SECONDS.sleep(1);
16+
} catch (InterruptedException e) {
17+
e.printStackTrace();
18+
}
19+
return 1;
20+
});
21+
22+
System.out.println("future.get() = " + future.get());
23+
24+
System.out.println(future.complete(-11) + "\t" + future.get());
25+
executor.shutdown();
26+
}
27+
28+
}

0 commit comments

Comments
 (0)