You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java-25/README.md
+24-33Lines changed: 24 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -29,21 +29,21 @@ To run each example use: `java --enable-preview --source 25 <FileName.java>`
29
29
***Structured Concurrency**
30
30
* re-preview with several API changes
31
31
* previous changes in [JDK 19](../java-19/README.md) and [JDK 21](../java-21/README.md)
32
-
* Joiners
32
+
* Joiners:
33
33
* introduce the concept of execution policy with `Joiner`
34
34
* Joiner object handles subtask completion and produces the outcome for the `join()` method
35
35
* depending on the joiner, the `join()` method may return a result, a stream of elements, or some other object
36
36
* the result of `join()` is useful when we don't handle each subtask individually, rather we want to wait for all subtasks to finish and then process the results (first result or all)
37
37
* a joiner instance should never be reused, always create a new instance
38
38
*`StructuredTaskScope` is open using static factory methods:
39
-
*`StructuredTaskScope.open()`: creates a scope with joiner strategy default of `StructuredTaskScope.Joiner.allSuccessfulOrThrow()` but `join()` will return null
40
-
*`StructuredTaskScope.open(StructuredTaskScope.Joiner)`: creates a scope with the specified joiner strategy
41
-
*`StructuredTaskScope.open(StructuredTaskScope.Joiner, Function)`: creates a scope with the specified joiner strategy and a function to customize the default configuration of the execution (name, thread factory and timeout)
42
-
* the scope can now be configured with a instace of [`Config`](https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.Config.html)
39
+
*`open()`: creates a scope with joiner strategy default of `StructuredTaskScope.Joiner.allSuccessfulOrThrow()` but `join()` will return null
40
+
*`open(StructuredTaskScope.Joiner)`: creates a scope with the specified joiner strategy
41
+
*`open(StructuredTaskScope.Joiner, Function)`: creates a scope with the specified joiner strategy and a function to customize the default configuration of the execution (name, thread factory and timeout)
42
+
* the scope can now be configured with a instance of [`Config`](https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.Config.html):
43
43
*`withName(String)`: sets the name of the scope to be monitored and managed
44
44
*`withThreadFactory(ThreadFactory)`: sets the thread factory to use for each subtask
45
45
*`withTimeout(Duration)`: sets the timeout for the scope, should use `Instant` to calculates the deadline (`Duration.between(Instant.now(), deadline)`)
46
-
*`Joiner` interface declares factory methods to create joiners for some common cases
46
+
*`Joiner` interface declares factory methods to create joiners for some common cases:
47
47
* interface:
48
48
```java
49
49
public interface Joiner<T, R> {
@@ -74,7 +74,7 @@ To run each example use: `java --enable-preview --source 25 <FileName.java>`
74
74
* waits all subtasks are completed or the predicate is satisfied to cancel the scope
75
75
*`join()` returns stream of all subtasks in the order they were forked
76
76
* each subtask can have the following states: `SUCCESS`, `FAILURE` or `UNAVAILABLE` (if the scope has been cancelled before it were forked or completed)
77
-
* predicate is of type[`Predicate<StructuredTaskScope.Subtask<? extends T>>`](https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/function/Predicate.html)
77
+
* predicate is an instance of[`Predicate<StructuredTaskScope.Subtask<? extends T>>`](https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/function/Predicate.html)
78
78
* each subtask that is completed successfully or failed will be passed to the predicate
79
79
* if the predicate returns true, the scope will be cancelled
80
80
* if throws an exception, `Thread.UncaughtExceptionHandler.uncaughtException` will be called
@@ -126,32 +126,23 @@ To run each example use: `java --enable-preview --source 25 <FileName.java>`
126
126
*`NoSuchElementException` if the scoped value is not bounded
127
127
* we can use `orElse` to set a default value if the scoped value is not bounded
128
128
*`SCOPE_KEY.getOrElse("default-value")`
129
-
* ex.:
130
-
*`run`:
131
-
```java
132
-
public final static ScopedValue<String> PRINCIPAL = ScopedValue.newInstance();
0 commit comments