Skip to content

Commit 8918105

Browse files
committed
Fix #68 Create VT via NettyScheduler
1 parent 70c03d8 commit 8918105

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

core/src/main/java/io/netty/loom/EventLoopScheduler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,12 @@ private static ThreadFactory newEventLoopSchedulerFactory(SharedRef sharedRef) {
113113
// enabling
114114
// work-stealing to change it for both
115115
var unstartedBuilder = Thread.ofVirtual();
116-
// we're not enforcing a preferred carrier on purpose, despite we could - to
117-
// prevent leaks to happen:
118-
// once this scheduler is gone, but a virtual thread is still to complete, we
119-
// would like to offload it
120-
// to the default scheduler rather than trying to reuse this scheduler's carrier
121-
// thread
122-
return runnable -> unstartedBuilder.unstarted(() -> runWithContext(runnable, sharedRef), null, sharedRef);
116+
NettyScheduler scheduler = NettyScheduler.INSTANCE;
117+
return runnable -> {
118+
var vTask = scheduler.newThread(unstartedBuilder, () -> runWithContext(runnable, sharedRef));
119+
vTask.attach(sharedRef);
120+
return vTask.thread();
121+
};
123122
}
124123

125124
private static void runWithContext(Runnable runnable, SharedRef sharedRef) {

core/src/main/java/io/netty/loom/NettyScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
public class NettyScheduler implements Thread.VirtualThreadScheduler {
4646

47-
private static volatile NettyScheduler INSTANCE;
47+
static volatile NettyScheduler INSTANCE;
4848

4949
private final Thread.VirtualThreadScheduler jdkBuildinScheduler;
5050

pom.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@
5858

5959
<build>
6060
<plugins>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-compiler-plugin</artifactId>
64+
<version>3.14.1</version>
65+
<configuration>
66+
<source>${java.version}</source>
67+
<target>${java.version}</target>
68+
<compilerArgs>
69+
<arg>--enable-preview</arg>
70+
</compilerArgs>
71+
</configuration>
72+
</plugin>
6173
<plugin>
6274
<groupId>com.diffplug.spotless</groupId>
6375
<artifactId>spotless-maven-plugin</artifactId>
@@ -96,18 +108,6 @@
96108
</plugins>
97109
<pluginManagement>
98110
<plugins>
99-
<plugin>
100-
<groupId>org.apache.maven.plugins</groupId>
101-
<artifactId>maven-compiler-plugin</artifactId>
102-
<version>3.14.1</version>
103-
<configuration>
104-
<source>${java.version}</source>
105-
<target>${java.version}</target>
106-
<compilerArgs>
107-
<arg>--enable-preview</arg>
108-
</compilerArgs>
109-
</configuration>
110-
</plugin>
111111
<plugin>
112112
<groupId>org.apache.maven.plugins</groupId>
113113
<artifactId>maven-surefire-plugin</artifactId>

0 commit comments

Comments
 (0)