|
2 | 2 |
|
3 | 3 | import io.netty.loom.EventLoopScheduler.SharedRef; |
4 | 4 |
|
5 | | -import java.lang.invoke.VarHandle; |
6 | 5 | import java.util.concurrent.ConcurrentHashMap; |
7 | 6 |
|
8 | 7 | /** |
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. |
21 | 29 | */ |
22 | 30 |
|
23 | 31 | public class NettyScheduler implements Thread.VirtualThreadScheduler { |
|
0 commit comments