Skip to content

Commit 6749c05

Browse files
committed
Refactor NettyScheduler documentation for clarity and accuracy
1 parent 990f3e2 commit 6749c05

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22

33
import io.netty.loom.EventLoopScheduler.SharedRef;
44

5-
import java.lang.invoke.VarHandle;
65
import java.util.concurrent.ConcurrentHashMap;
76

87
/**
9-
* Global scheduler — provides execution for virtual threads that do not specify
10-
* their own scheduler. Note: this is not a real scheduler, but merely a
11-
* proxy/dispatcher for schedulers. 1. Platform threads → delegate to the
12-
* built-in ForkJoin scheduler. 2. Virtual threads derived from a
13-
* VirtualThreadNettyScheduler → continue using that same
14-
* VirtualThreadNettyScheduler. 3. Other virtual threads → use the default
15-
* JDK-provided scheduler. 4. Virtual threads spawned by case (2) → still use
16-
* the originating VirtualThreadNettyScheduler. 5. Poller: - VTHREAD_POLLERS →
17-
* not relevant here; simply use the JDK’s built-in scheduler. -
18-
* POLLER_PER_CARRIER → initialized lazily upon first network I/O usage, so as
19-
* long as this GlobalDelegateThreadNettyScheduler correctly “inherits” the
20-
* actual underlying scheduler, it will work properly.
8+
* Global Netty scheduler proxy for virtual threads.
9+
*
10+
* <p>Exact inheritance rule: a newly started virtual thread will inherit the
11+
* caller's {@code EventLoopScheduler} only when both of the following are true:
12+
* <ul>
13+
* <li>{@code jdk.pollerMode} is {@code 3} (per-carrier pollers); and</li>
14+
* <li>the thread performing the start/poller I/O is itself run by an
15+
* {@code EventLoopScheduler} (i.e. the current thread's
16+
* {@code EventLoopScheduler.currentThreadSchedulerContext().scheduler()} is
17+
* non-null).</li>
18+
* </ul>
19+
*
20+
* <p>If either condition is false the virtual thread does not inherit an
21+
* {@code EventLoopScheduler} and falls back to the default JDK scheduler.
22+
*
23+
* <p>Implementation note: the current implementation attempts inheritance only
24+
* for poller-created virtual threads (recognized by the {@code "-Read-Poller"}
25+
* name suffix).
26+
*
27+
* <p>This class is a proxy/dispatcher; see {@link EventLoopScheduler} for
28+
* details about scheduler attachment and execution.
2129
*/
2230

2331
public class NettyScheduler implements Thread.VirtualThreadScheduler {

0 commit comments

Comments
 (0)