reformat source code

main
Sandro Leuchter 2026-06-20 09:25:29 +00:00
parent daf6e7341d
commit c89682b3fb
1 changed files with 36 additions and 34 deletions

View File

@ -1,34 +1,36 @@
package pp; package pp;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class Main { public class Main {
public static void main(String... args) { public static void main(String... args) {
var executor = Executors.newCachedThreadPool(); var executor = Executors.newCachedThreadPool();
// Lambda-Ausdruck, mehrere Statements, explizites return // Lambda-Ausdruck, mehrere Statements, explizites return
var f1 = executor.submit(() -> { var f1 = executor.submit(() -> {
return 1.0 + 2.0; return 1.0 + 2.0;
}); });
// Callable als Inner Class // Callable als Inner Class
var f2 = executor.submit(new Callable<Double>() { var f2 = executor.submit(
@Override new Callable<Double>() {
public Double call() throws Exception { @Override
return 3.0 + 4.0; public Double call() throws Exception {
} return 3.0 + 4.0;
}); }
// Lambda-Ausdruck, knapp }
var f3 = executor.submit(() -> f1.get() + f2.get()); );
try { // Lambda-Ausdruck, knapp
// get() blockiert, bis etwas vorliegt (auch oben) var f3 = executor.submit(() -> f1.get() + f2.get());
System.out.println(f3.get()); try {
} catch (InterruptedException | ExecutionException e) { // get() blockiert, bis etwas vorliegt (auch oben)
// Exceptions in f1 und f2 werden bis zum f3.get() verzögert System.out.println(f3.get());
Thread.currentThread().interrupt(); } catch (InterruptedException | ExecutionException e) {
} finally { // Exceptions in f1 und f2 werden bis zum f3.get() verzögert
executor.shutdown(); Thread.currentThread().interrupt();
} } finally {
} executor.shutdown();
} }
}
}