<div class="__aliyun_email_body_block"><div  style="clear:both;"><span  style="font-family:Helvetica,Tahoma,Arial;">> What you are doing seems very risky at this point in release cycle of virtual threads. I would return to my original question of what are you trying to accomplish and maybe people can help with a simpler and supported way of doing that.</span><br ></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;">What I want to do: Using virtual thread to make code simpler, otherwise I have to make use of `Future.reduce/traverse` thing, and make code faster (blocking HTTP client)/</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;">What's unexpected, when it hang, the JVM makes no progress , jcmd no responding too.</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;"><br ></span></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;">发件人:robert engels <rengels@ix.netcom.com></div><div  style="clear:both;">发送时间:2024年6月4日(星期二) 22:07</div><div  style="clear:both;">收件人:"何品(虎鸣)"<hepin.p@alibaba-inc.com></div><div  style="clear:both;">抄 送:"loom-dev"<loom-dev@openjdk.org></div><div  style="clear:both;">主 题:Re: Virtual thread hang and all threads stop running on JDK21</div><div  style="clear:both;"><br ></div>This might cause everything to hang - because if all “carriers” in the pool end up blocked, no compensation threads will be added, leading to carrier thread starvation. Not saying that is the underlying cause though.<div  class=""><br  class=""></div><div  class="">What you are doing seems very risky at this point in release cycle of virtual threads. I would return to my original question of what are you trying to accomplish and maybe people can help with a simpler and supported way of doing that.<br  class=""><div ><br  class=""><div  style="margin:14.0px 40.0px;"><div  class="">On Jun 4, 2024, at 9:00 AM, robert engels <<a  class="" href="mailto:rengels@ix.netcom.com" target="_blank">rengels@ix.netcom.com</a>> wrote:</div><br  class="Apple-interchange-newline"><div  class="" style="overflow-wrap:break-word;">If you look at the Blocker class, if your virtual thread carrier thread is not an instance of CarrierThread, then code like this will not do what is expected:<div  class=""><br  class=""></div><div  class="">    public static long begin() {<br  class="">        if (VM.isBooted()<br  class="">                && currentCarrierThread() instanceof CarrierThread ct && !ct.inBlocking()) {<br  class="">            ct.beginBlocking();<br  class="">            boolean completed = false;<br  class="">            try {<br  class="">                long comp = ForkJoinPools.beginCompensatedBlock(ct.getPool());<br  class="">                assert currentCarrierThread() == ct;<br  class="">                completed = true;<br  class="">                return comp;<br  class="">            } finally {<br  class="">                if (!completed) {<br  class="">                    ct.endBlocking();<br  class="">                }<br  class="">            }<br  class="">        }<br  class="">        return -1;<br  class="">    }<br  class=""><div  class=""><br  class=""></div><div  class="">I am surprised that anything works at all. You may have success if you make your executor create instances of CarrierThread - which is public.</div><div  class=""><br  class=""></div><div  class=""><br  class=""><div  class="">On Jun 4, 2024, at 8:44 AM, robert engels <<a  class="" href="mailto:rengels@ix.netcom.com" target="_blank">rengels@ix.netcom.com</a>> wrote:</div><br  class="Apple-interchange-newline"><div  class="" style="overflow-wrap:break-word;">What are you trying to do? I am pretty sure the current scheduler is tied directly to the implementation and if you change it, I am not surprised that things don’t work. The default scheduler creates instances of CarrierThread which has special properties. It is doubtful yours does.<br  class=""><div  class=""><br  class=""><div  class="">On Jun 4, 2024, at 8:29 AM, 何品(虎鸣) <<a  class="" href="mailto:hepin.p@alibaba-inc.com" target="_blank">hepin.p@alibaba-inc.com</a>> wrote:</div><br  class="Apple-interchange-newline"><div  class="" style="line-height:1.7;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;"><div  class="" style="clear:both;"><br  class=""></div><div  class="" 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  class="" style="clear:both;">We try to separate the Virtual Thread's scheduler with reflections. but that does not work too.</div><div  class="" style="clear:both;"><br  class=""></div><div  class="" style="clear:both;">Our userbase are pretty simple:</div><div  class="" style="clear:both;">A: VT Executor backing by 128-sized ThreadPoolExecutor for running java code with `CompletableFuture.get`</div><div  class="" 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  class="" style="clear:both;"><br  class=""></div><div  class="" style="clear:both;">Even if A and B are using Different backing ThreadPool, they all stop responding。</div><div  class="" style="clear:both;"><br  class=""></div><div  class="" style="clear:both;"><br  class=""></div><div  class="" style="clear:both;"><br  class=""></div><div  class="" style="clear:both;">```java</div><div  class=" __aliyun_node_has_color __aliyun_node_has_bgcolor" style="clear:both;background-color:#1e1f22;color:#bcbec4;"><pre  class="" 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  class="">                                      <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final boolean </span>enabled,<br  class="">                                      <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  class=""></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  class=""></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">            </span><span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">return </span>executor;<br  class="">        <span  class=" __aliyun_node_has_color" style="color:#359ff4;">}<br  class=""></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  class=""></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  class="" style="font-style:italic;">ofVirtual</span><span  class=" __aliyun_node_has_color" style="color:#e8ba36;">()</span>;<br  class="">            <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  class=""></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  class="">                <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">final var </span>privateLookup = MethodHandles.<span  class="" 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  class="">                <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  class="">                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  class="">            <span  class=" __aliyun_node_has_color" style="color:#6e7ed9;">}<br  class=""></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  class="">            <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  class="">            <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">return </span>Executors.<span  class="" 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  class="">        <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  class=""></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  class="">            <span  class=" __aliyun_node_has_color" style="color:#cf8e6d;">return </span>executor;<br  class="">        <span  class=" __aliyun_node_has_color" style="color:#359ff4;">}<br  class=""></span><span  class=" __aliyun_node_has_color" style="color:#359ff4;">    </span><span  class=" __aliyun_node_has_color" style="color:#54a857;">}<br  class=""></span><br  class=""></pre></div></div></div><br  class=""></div></div><br  class=""></div></div></div></div><br  class=""></div></blockquote></div>