From af530bde08025a5b7daaf02400ebd1b8b73b3049 Mon Sep 17 00:00:00 2001 From: 2wenty1ne Date: Tue, 29 Oct 2024 15:45:54 +0100 Subject: [PATCH] c --- src/src/Main.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/src/Main.java diff --git a/src/src/Main.java b/src/src/Main.java new file mode 100644 index 0000000..fdaa1f8 --- /dev/null +++ b/src/src/Main.java @@ -0,0 +1,28 @@ +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; + +public class Main { + public static void main(String... args) { + var executor = Executors.newCachedThreadPool(); + Callable c = new Callable<>() { + public Integer call() { + return 1 + 2; + } + }; + var f1 = executor.submit(c); + var f2 = executor.submit(() -> { + return 3 + 4; + }); + + var f3 = executor.submit(() -> f1.get() + f2.get()); + + try { + System.out.printf("Res: %d \n", f3.get()); + } catch (ExecutionException | InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + executor.shutdown(); + } + } +} \ No newline at end of file