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;
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();
// Lambda-Ausdruck, mehrere Statements, explizites return
var f1 = executor.submit(() -> {
return 1.0 + 2.0;
});
// Callable als Inner Class
var f2 = executor.submit(new Callable<Double>() {
@Override
public Double call() throws Exception {
return 3.0 + 4.0;
}
});
// Lambda-Ausdruck, knapp
var f3 = executor.submit(() -> f1.get() + f2.get());
try {
// get() blockiert, bis etwas vorliegt (auch oben)
System.out.println(f3.get());
} catch (InterruptedException | ExecutionException e) {
// Exceptions in f1 und f2 werden bis zum f3.get() verzögert
Thread.currentThread().interrupt();
} finally {
executor.shutdown();
}
}
}
package pp;
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();
// Lambda-Ausdruck, mehrere Statements, explizites return
var f1 = executor.submit(() -> {
return 1.0 + 2.0;
});
// Callable als Inner Class
var f2 = executor.submit(
new Callable<Double>() {
@Override
public Double call() throws Exception {
return 3.0 + 4.0;
}
}
);
// Lambda-Ausdruck, knapp
var f3 = executor.submit(() -> f1.get() + f2.get());
try {
// get() blockiert, bis etwas vorliegt (auch oben)
System.out.println(f3.get());
} catch (InterruptedException | ExecutionException e) {
// Exceptions in f1 und f2 werden bis zum f3.get() verzögert
Thread.currentThread().interrupt();
} finally {
executor.shutdown();
}
}
}