Skip to content

Commit c256ee6

Browse files
committed
format
1 parent 07addbf commit c256ee6

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

java-25/README.md

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ To run each example use: `java --enable-preview --source 25 <FileName.java>`
2929
* **Structured Concurrency**
3030
* re-preview with several API changes
3131
* previous changes in [JDK 19](../java-19/README.md) and [JDK 21](../java-21/README.md)
32-
* Joiners
32+
* Joiners:
3333
* introduce the concept of execution policy with `Joiner`
3434
* Joiner object handles subtask completion and produces the outcome for the `join()` method
3535
* depending on the joiner, the `join()` method may return a result, a stream of elements, or some other object
3636
* 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)
3737
* a joiner instance should never be reused, always create a new instance
3838
* `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):
4343
* `withName(String)`: sets the name of the scope to be monitored and managed
4444
* `withThreadFactory(ThreadFactory)`: sets the thread factory to use for each subtask
4545
* `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:
4747
* interface:
4848
```java
4949
public interface Joiner<T, R> {
@@ -74,7 +74,7 @@ To run each example use: `java --enable-preview --source 25 <FileName.java>`
7474
* waits all subtasks are completed or the predicate is satisfied to cancel the scope
7575
* `join()` returns stream of all subtasks in the order they were forked
7676
* 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)
7878
* each subtask that is completed successfully or failed will be passed to the predicate
7979
* if the predicate returns true, the scope will be cancelled
8080
* 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>`
126126
* `NoSuchElementException` if the scoped value is not bounded
127127
* we can use `orElse` to set a default value if the scoped value is not bounded
128128
* `SCOPE_KEY.getOrElse("default-value")`
129-
* ex.:
130-
* `run`:
131-
```java
132-
public final static ScopedValue<String> PRINCIPAL = ScopedValue.newInstance();
133-
ScopedValue.where(PRINCIPAL, "guest")
134-
.run(() -> {
135-
var userRole = PRINCIPAL.get();
136-
});
137-
```
138-
* `call`:
139-
```java
140-
public final static ScopedValue<String> PRINCIPAL = ScopedValue.newInstance();
141-
var userRole = ScopedValue.where(PRINCIPAL, "guest")
142-
.call(() -> {
143-
return "Value: " + PRINCIPAL.get();
144-
});
145-
```
146-
* ex.:
147-
*
148-
```java
149-
var universeAnswer = ScopedValue.where(SUBJECT, "Deep Thought")
150-
.call(() -> {
151-
// some magic
152-
return 42;
153-
});
154-
```
129+
* ex.:
130+
* `run`:
131+
```java
132+
public final static ScopedValue<String> PRINCIPAL = ScopedValue.newInstance();
133+
ScopedValue.where(PRINCIPAL, "guest")
134+
.run(() -> {
135+
var userRole = PRINCIPAL.get();
136+
});
137+
```
138+
* `call`:
139+
```java
140+
public final static ScopedValue<String> PRINCIPAL = ScopedValue.newInstance();
141+
var userRole = ScopedValue.where(PRINCIPAL, "guest")
142+
.call(() -> {
143+
return "Value: " + PRINCIPAL.get();
144+
});
145+
```
155146
* virtual thread and cross-thread sharing
156147
* to share data between a thread and its child thread we need to make the scoped values inherited by child thread
157148
* we can use the Structured Concurrency API

0 commit comments

Comments
 (0)