@SneakyThrows
public static void main(String[] args) {
ThreadPoolExecutor executorService = new ThreadPoolExecutor(
8,
10,
1L,
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(100),
new ThreadPoolExecutor.CallerRunsPolicy());
CompletableFuture<DemandFile> future1 = CompletableFuture.supplyAsync(() -> {
System.out.println("任务一开始");
DemandFile file = new DemandFile();
file.setId("1");
return file;
});
CompletableFuture<DemandFile> future2 = CompletableFuture.supplyAsync(() -> {
System.out.println("任务二开始");
DemandFile file = new DemandFile();
file.setId("2");
return file;
});
future1.thenAcceptBothAsync(future2, (result1, result2) -> {
System.out.println("感知任务一和任务二完成,执行任务三"+result1+"-----"+result2);
});
CompletableFuture<String> future = future1.thenCombineAsync(future2, (f1, f2) -> {
return f1 + ":" + f2 + "-> hello";
});