Files
javademos/jep-tour/src/broken/StructuredScope26.java
T

24 lines
1.0 KiB
Java

import java.util.List;
import java.util.concurrent.StructuredTaskScope;
import java.util.concurrent.StructuredTaskScope.Joiner;
/**
* JDK 26 code for the structured concurrency preview. It compiles on 26 and fails on 27:
* StructuredTaskScope gained a third type parameter (the exception join() throws), and
* FailedException / TimeoutException no longer exist. Driven by scripts/broken-on-27.sh.
*/
public class StructuredScope26 {
public static void main(String[] args) throws Exception {
try (StructuredTaskScope<String, List<String>> scope =
StructuredTaskScope.open(Joiner.<String>allSuccessfulOrThrow())) {
scope.fork(() -> "price=42");
List<String> results = scope.join();
System.out.println(results);
} catch (StructuredTaskScope.FailedException e) {
System.out.println("a subtask failed: " + e.getCause());
} catch (StructuredTaskScope.TimeoutException e) {
System.out.println("timed out");
}
}
}