main
commit
af530bde08
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue