<div class="__aliyun_email_body_block"><div  style="line-height:1.7;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><div  style="clear:both;">eg: the code below, seems like the VM is corrupted <br ></div><div  style="clear:both;"><br ></div><div  style="clear:both;"><br ></div><div  style="clear:both;"><div  style="background-color:#1e1f22;color:#bcbec4;"><pre  style="font-family:'Source Code Pro',monospace;font-size:20.0px;"><span  style="color:#cf8e6d;">private static final </span>ThreadPoolExecutor <span  style="color:#c77dbb;font-style:italic;">EXECUTOR </span>= <span  style="color:#cf8e6d;">new </span>ThreadPoolExecutor<span  style="color:#e8ba36;">(<br ></span><span  style="color:#e8ba36;">    </span><span  style="color:#2aacb8;">128</span>,<br >    <span  style="color:#2aacb8;">128</span>,<br >    <span  style="color:#2aacb8;">60</span>,<br >    TimeUnit.<span  style="color:#c77dbb;font-style:italic;">SECONDS</span>,<br >    <span  style="color:#cf8e6d;">new </span>LinkedBlockingDeque<span  style="color:#e8ba36;"><></span><span  style="color:#54a857;">()</span>,<br >    <span  style="color:#cf8e6d;">new </span>NamedThreadFactory<span  style="color:#54a857;">(</span><span  style="color:#6aab73;">"OrderedTaskRunnerCarrier"</span><span  style="color:#54a857;">)</span><span  style="color:#e8ba36;">)</span>;<br ><br ><span  style="color:#cf8e6d;">static </span><span  style="color:#54a857;">{<br ></span><span  style="color:#54a857;">    </span><span  style="color:#c77dbb;font-style:italic;">EXECUTOR</span>.prestartAllCoreThreads<span  style="color:#e8ba36;">()</span>;<br ><span  style="color:#54a857;">}<br ></span><span  style="color:#54a857;"><br ></span><span  style="color:#cf8e6d;">private static final </span>Executor <span  style="color:#c77dbb;font-style:italic;">VTExecutor </span>= VirtualThreadSupport.<span  style="font-style:italic;">virtualize</span><span  style="color:#e8ba36;">(<br ></span><span  style="color:#e8ba36;">    </span><span  style="color:#6aab73;">"OrderedTaskRunner"</span>,<br >    <span  style="color:#cf8e6d;">false</span>,<br >    <span  style="color:#c77dbb;font-style:italic;">EXECUTOR</span><span  style="color:#e8ba36;">)</span>;</pre></div></div><blockquote  style="margin-right:.0px;margin-top:.0px;margin-bottom:.0px;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><div  style="clear:both;">------------------------------------------------------------------</div><div  style="clear:both;">发件人:何品(虎鸣) <hepin.p@alibaba-inc.com></div><div  style="clear:both;">发送时间:2024年6月4日(星期二) 21:29</div><div  style="clear:both;">收件人:loom-dev <loom-dev@openjdk.org></div><div  style="clear:both;">主 题:Virtual thread hang and all threads stop running on JDK21</div><div  style="clear:both;"><br ></div><div  class=" __aliyun_node_has_color" style="line-height:1.7;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><div  style="clear:both;"><br ></div><div  style="clear:both;">Hi, we are using Virtual threads on JDK21.0.2, and find it can stop running, all threads stopped/hung, and we can't even call thread dump.</div><div  style="clear:both;">We try to separate the Virtual Thread's scheduler with reflections. but that does not work too.</div><div  style="clear:both;"><br ></div><div  style="clear:both;">Our userbase are pretty simple:</div><div  style="clear:both;">A: VT Executor backing by 128-sized ThreadPoolExecutor for running java code with `CompletableFuture.get`</div><div  style="clear:both;">B: VT Executor backing by 64-sized ThreadPoolExecutor for retrieving data with HTTP client, with max concurrency to 3000 (virtual threads)</div><div  style="clear:both;"><br ></div><div  style="clear:both;">Even if A and B are using Different backing ThreadPool, they all stop responding。</div><div  style="clear:both;"><br ></div><div  style="clear:both;"><br ></div><div  style="clear:both;"><br ></div><div  style="clear:both;">```java</div><div  class=" __aliyun_node_has_color __aliyun_node_has_bgcolor" style="clear:both;background-color:#1e1f22;color:#bcbec4;"><pre  style="font-family:'Source Code Pro',monospace;font-size:20.0px;">    <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">public static </span>Executor <span  class=" __aliyun_node_has_color" style="color:#56a8f5;">virtualize</span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">(</span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final </span>String prefix,<br >                                      <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final boolean </span>enabled,<br >                                      <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final </span>Executor executor<span  class=" __aliyun_node_has_color" style="color:#e8ba36;">) </span><span  class=" __aliyun_node_has_color" style="color:#54a857;">{<br ></span><span  class=" __aliyun_node_has_color" style="color:#54a857;">        </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">if </span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">(</span>!enabled<span  class=" __aliyun_node_has_color" style="color:#e8ba36;">) </span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">{<br ></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">            </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">return </span>executor;<br >        <span  class=" __aliyun_node_has_color" style="color:#359ff4;">}<br ></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">        </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">try </span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">{<br ></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">            </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final var </span>builder = Thread.<span  style="font-style:italic;">ofVirtual</span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">()</span>;<br >            <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">if </span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">(</span>executor != <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">null</span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">) </span><span  class=" __aliyun_node_has_color" style="color:#6e7ed9;">{<br ></span><span  class=" __aliyun_node_has_color" style="color:#6e7ed9;">                </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final var </span>clazz = builder.getClass<span  class=" __aliyun_node_has_color" style="color:#54a857;">()</span>;<br >                <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final var </span>privateLookup = MethodHandles.<span  style="font-style:italic;">privateLookupIn</span><span  class=" __aliyun_node_has_color" style="color:#54a857;">(</span>clazz, <span  class=" __aliyun_node_has_color" style="color:#c77dbb;font-style:italic;">lookup</span><span  class=" __aliyun_node_has_color" style="color:#54a857;">)</span>;<br >                <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final var </span>schedulerFieldSetter = privateLookup.findSetter<span  class=" __aliyun_node_has_color" style="color:#54a857;">(</span>clazz, <span  class=" __aliyun_node_has_color" style="color:#6aab73;">"scheduler"</span>, Executor.<span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">class</span><span  class=" __aliyun_node_has_color" style="color:#54a857;">)</span>;<br >                schedulerFieldSetter.invoke<span  class=" __aliyun_node_has_color" style="color:#54a857;">(</span>builder, executor<span  class=" __aliyun_node_has_color" style="color:#54a857;">)</span>;<br >            <span  class=" __aliyun_node_has_color" style="color:#6e7ed9;">}<br ></span><span  class=" __aliyun_node_has_color" style="color:#6e7ed9;">            </span>builder.name<span  class=" __aliyun_node_has_color" style="color:#e8ba36;">(</span>prefix + <span  class=" __aliyun_node_has_color" style="color:#6aab73;">"-virtual-thread-"</span>, <span  class=" __aliyun_node_has_color" style="color:#2aacb8;">0L</span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">)</span>;<br >            <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final var </span>factory = builder.factory<span  class=" __aliyun_node_has_color" style="color:#e8ba36;">()</span>;<br >            <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">return </span>Executors.<span  style="font-style:italic;">newThreadPerTaskExecutor</span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">(</span>factory<span  class=" __aliyun_node_has_color" style="color:#e8ba36;">)</span>;<br >        <span  class=" __aliyun_node_has_color" style="color:#359ff4;">} </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">catch </span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">(</span>Throwable e<span  class=" __aliyun_node_has_color" style="color:#e8ba36;">) </span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">{<br ></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">            </span><span  class=" __aliyun_node_has_color" style="color:#c77dbb;font-style:italic;">log</span>.error<span  class=" __aliyun_node_has_color" style="color:#54a857;">(</span><span  class=" __aliyun_node_has_color" style="color:#6aab73;">"Error when virtualize a executor"</span>, e<span  class=" __aliyun_node_has_color" style="color:#54a857;">)</span>;<br >            <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">return </span>executor;<br >        <span  class=" __aliyun_node_has_color" style="color:#359ff4;">}<br ></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">    </span><span  class=" __aliyun_node_has_color" style="color:#54a857;">}<br ></span><br ></pre></div></div></blockquote></div></div>