Skip to content

Commit 8b2f5a2

Browse files
committed
compiles with jdk 21
1 parent 3b0e2cb commit 8b2f5a2

File tree

10 files changed

+22
-48
lines changed

10 files changed

+22
-48
lines changed

build-all.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ cd $MY_HOME/egg__10_sc_nested_scopes_thread_dump
4040
cd $MY_HOME/egg__10b_sc_nested_experiment
4141
./clean.sh && ./compile.sh
4242

43-
exit 0
44-
4543
cd $MY_HOME/egg__11_sc_utility
4644
./clean.sh && ./compile.sh
4745

egg_StackOverflow_74464598/compile.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ TARGET_DIR=$ROOT_DIR/my_build/main
1010

1111
mkdir -p $TARGET_DIR
1212

13-
javac --release 19 --enable-preview \
13+
javac --release 21 --enable-preview \
1414
-cp $CLASSPATH \
15-
--add-modules jdk.incubator.concurrent \
1615
-d $TARGET_DIR `find $SRC_DIR -name "*.java"`
1716

1817
echo "compile ok"

egg_StackOverflow_74464598/src/main/java/net/codetojoy/Runner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// note: I no longer own this domain
33
package net.codetojoy;
44

5-
import jdk.incubator.concurrent.*;
6-
7-
// javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
5+
import java.util.concurrent.*;
86

97
public class Runner {
108
String runInThread(boolean doShutdown) throws Exception {
119
try (var scope = new StructuredTaskScope<String>()) {
1210
var future = scope.fork(() -> new TaskRunner(doShutdown).run());
1311
scope.join();
14-
return future.resultNow();
12+
return future.get();
1513
}
1614
}
1715

egg_StackOverflow_74464598/src/main/java/net/codetojoy/TaskRunner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
package net.codetojoy;
44

55
import java.util.concurrent.Future;
6-
import jdk.incubator.concurrent.StructuredTaskScope;
7-
8-
// javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
6+
import java.util.concurrent.StructuredTaskScope;
97

108
public class TaskRunner {
119
private long taskDelayInMillis = 20_000L;
@@ -56,7 +54,7 @@ public String run() throws Exception {
5654
scope.join();
5755
scope.throwIfFailed();
5856

59-
result = numOrders.resultNow() + " " + price.resultNow();
57+
result = numOrders.get() + " " + price.get();
6058

6159
System.out.println("TRACER TaskRunner post result");
6260
} catch (Exception ex) {

egg__11_sc_utility/compile.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ TARGET_DIR=$ROOT_DIR/my_build/main
1010

1111
mkdir -p $TARGET_DIR
1212

13-
javac --release 19 --enable-preview \
13+
javac --release 21 --enable-preview \
1414
-cp $CLASSPATH \
15-
--add-modules jdk.incubator.concurrent \
1615
-d $TARGET_DIR `find $SRC_DIR -name "*.java"`
1716

1817
echo "compile ok"

egg__11_sc_utility/src/main/java/net/codetojoy/CustomScope.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
import java.util.concurrent.*;
88
import java.util.concurrent.atomic.*;
99

10-
import jdk.incubator.concurrent.StructuredTaskScope;
11-
12-
// javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
13-
14-
// NOTE: this is NOT production-ready, just an experiment
15-
//
16-
// ref: https://github.com/openjdk/jdk19/blob/master/src/jdk.incubator.concurrent/share/classes/jdk/incubator/concurrent/StructuredTaskScope.java
17-
1810
class CustomScope<T> extends StructuredTaskScope<T> {
1911
private final Queue<T> results = new ConcurrentLinkedQueue<>();
2012

@@ -23,9 +15,9 @@ class CustomScope<T> extends StructuredTaskScope<T> {
2315
}
2416

2517
@Override
26-
protected void handleComplete(Future<T> future) {
27-
if (future.state() == Future.State.SUCCESS) {
28-
T result = future.resultNow();
18+
protected void handleComplete(StructuredTaskScope.Subtask<? extends T> subtask) {
19+
if (subtask.state() == StructuredTaskScope.Subtask.State.SUCCESS) {
20+
T result = subtask.get();
2921
results.add(result);
3022
}
3123
}

egg__11_sc_utility/src/main/java/net/codetojoy/Runner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
// note: I no longer own this domain
33
package net.codetojoy;
44

5-
import jdk.incubator.concurrent.StructuredTaskScope;
5+
import java.util.concurrent.StructuredTaskScope;
66

77
import java.time.Instant;
88
import java.io.*;
99
import java.util.*;
1010
import java.util.stream.Stream;
1111

12-
// javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
13-
1412
public class Runner {
1513
private static final int TIMEOUT_IN_SECONDS = 10;
1614

@@ -36,7 +34,7 @@ void run() throws Exception {
3634
var deadline = Instant.now().plusSeconds(TIMEOUT_IN_SECONDS);
3735
scope.joinUntil(deadline);
3836

39-
var infos = foo.resultNow();
37+
var infos = foo.get();
4038
infos.forEach((info) -> {
4139
System.out.println("TRACER received: " + info.toString());
4240
});

egg__11b_sc_utility/compile.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ TARGET_DIR=$ROOT_DIR/my_build/main
1010

1111
mkdir -p $TARGET_DIR
1212

13-
javac --release 19 --enable-preview \
13+
javac --release 21 --enable-preview \
1414
-cp $CLASSPATH \
15-
--add-modules jdk.incubator.concurrent \
1615
-d $TARGET_DIR `find $SRC_DIR -name "*.java"`
1716

1817
echo "compile ok"

egg__11b_sc_utility/src/main/java/net/codetojoy/InvokeAllScope.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,29 @@
77
import java.util.concurrent.*;
88
import java.util.concurrent.atomic.*;
99

10-
import jdk.incubator.concurrent.StructuredTaskScope;
11-
12-
// javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
13-
1410
// NOTE: this is NOT production-ready, just an experiment
1511
//
16-
// ref: https://github.com/openjdk/jdk19/blob/master/src/jdk.incubator.concurrent/share/classes/jdk/incubator/concurrent/StructuredTaskScope.java
1712

1813
public class InvokeAllScope<T> extends StructuredTaskScope<T> {
1914
private final Queue<T> results = new ConcurrentLinkedQueue<>();
2015
private final AtomicInteger successCounter = new AtomicInteger(0);
2116
private final AtomicInteger failureCounter = new AtomicInteger(0);
22-
private final AtomicInteger cancelCounter = new AtomicInteger(0);
17+
private final AtomicInteger unavailableCounter = new AtomicInteger(0);
2318

2419
public InvokeAllScope() {
2520
super(null, Thread.ofVirtual().factory());
2621
}
2722

2823
@Override
29-
protected void handleComplete(Future<T> future) {
30-
if (future.state() == Future.State.SUCCESS) {
31-
T result = future.resultNow();
24+
protected void handleComplete(StructuredTaskScope.Subtask<? extends T> subtask) {
25+
if (subtask.state() == StructuredTaskScope.Subtask.State.SUCCESS) {
26+
T result = subtask.get();
3227
results.add(result);
3328
successCounter.getAndIncrement();
34-
} else if (future.state() == Future.State.FAILED) {
29+
} else if (subtask.state() == StructuredTaskScope.Subtask.State.FAILED) {
3530
failureCounter.getAndIncrement();
36-
} else if (future.state() == Future.State.CANCELLED) {
37-
cancelCounter.getAndIncrement();
31+
} else if (subtask.state() == StructuredTaskScope.Subtask.State.UNAVAILABLE) {
32+
unavailableCounter.getAndIncrement();
3833
}
3934
}
4035

@@ -43,7 +38,7 @@ private void emitCounters() {
4338
if (doEmit) {
4439
System.out.println("TRACER scope # success: " + successCounter.get());
4540
System.out.println("TRACER scope # failure: " + failureCounter.get());
46-
System.out.println("TRACER scope # cancel : " + cancelCounter.get());
41+
System.out.println("TRACER scope # unavailable : " + unavailableCounter.get());
4742
}
4843
}
4944

egg__11b_sc_utility/src/main/java/net/codetojoy/Runner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
// note: I no longer own this domain
33
package net.codetojoy;
44

5-
import jdk.incubator.concurrent.StructuredTaskScope;
5+
import java.util.concurrent.StructuredTaskScope;
66

77
import java.time.Instant;
88
import java.io.*;
99
import java.util.*;
1010
import java.util.stream.Stream;
1111

12-
// javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
13-
1412
public class Runner {
1513
private static final int TIMEOUT_IN_SECONDS = 10;
1614

@@ -36,7 +34,7 @@ void run() throws Exception {
3634
var deadline = Instant.now().plusSeconds(TIMEOUT_IN_SECONDS);
3735
scope.joinUntil(deadline);
3836

39-
var infos = foo.resultNow();
37+
var infos = foo.get();
4038
infos.forEach((info) -> {
4139
System.out.println("TRACER received: " + info.toString());
4240
});

0 commit comments

Comments
 (0)