2wenty1ne 2024-10-29 15:45:54 +01:00
commit af530bde08
1 changed files with 28 additions and 0 deletions

28
src/src/Main.java 100644
View File

@ -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<Integer> 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();
}
}
}