<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;">Thanks for the update, will that change be backport to j21u?</div><div style="clear:both;"><br ></div><div style="clear:both;">more context information:</div><div style="clear:both;"><br ></div><div style="clear:both;">I was using it as</div><div style="clear:both;">```</div><div style="clear:both;"><span > public static final ThreadFactory newVirtualThreadFactory(final String prefix) {<br ></span><div style="clear:both;"> return Thread.ofVirtual()<br ></div><div style="clear:both;"> .name(prefix + "-")<br ></div><div style="clear:both;"> .uncaughtExceptionHandler((t, e) -> {<br ></div><div style="clear:both;"> log.error("Uncaught exception in HSF biz processor, thread:[{}]", t, e);<br ></div><div style="clear:both;"> })<br ></div><div style="clear:both;"> .factory();<br ></div><div ><span > }</span></div><span ><br ></span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;"><span > private static final ThreadFactory THREAD_FACTORY = newVirtualThreadFactory("HSFBizProcessor-VIRTUAL-");<br ></span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;"><span > private final Lazy<LogAwareThreadPoolExecutor> executor = Lazy.of(() -> {<br ></span><div style="clear:both;"> final var executor = new LogAwareThreadPoolExecutor(<br ></div><div style="clear:both;"> 32,<br ></div><div style="clear:both;"> 2500, //max threads<br ></div><div style="clear:both;"> 60,<br ></div><div style="clear:both;"> TimeUnit.SECONDS,<br ></div><div style="clear:both;"> new SynchronousQueue<>(false),<br ></div><div style="clear:both;"> THREAD_FACTORY,<br ></div><div style="clear:both;"> new ThreadPoolExecutor.AbortPolicy());</div><div style="clear:both;"> return executor;<br ></div><span > });</span></div><div style="clear:both;"><span >```</span></div><div style="clear:both;">and there are other executors too.</div><div style="clear:both;"><br ></div><div style="clear:both;">And when I testing , the threads' number grows to <span style="color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:.0px;text-transform:none;word-spacing:.0px;white-space:normal;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline;">2205.</span></div><div style="clear:both;"><span style="color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:.0px;text-transform:none;word-spacing:.0px;white-space:normal;text-decoration-thickness:initial;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline;"><br ></span></div><div style="clear:both;">And now I just add the `<span >executor.allowCoreThreadTimeOut(true);` too all `ThreadPoolExecutor` which child thread is actual a virtual thread, seems not help much.</span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;">I think I should change the code to use the `<span >Semaphore` and never pooling</span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;"><span ><br ></span></div><div style="clear:both;"><br /></div><blockquote style="margin-right:0;margin-top:0;margin-bottom:0;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><div style="clear:both;">------------------------------------------------------------------</div><div style="clear:both;">发件人:Alan Bateman <Alan.Bateman@oracle.com></div><div style="clear:both;">发送时间:2024年1月12日(星期五) 20:38</div><div style="clear:both;">收件人:何品(虎鸣) <hepin.p@alibaba-inc.com>; loom-dev <loom-dev@openjdk.org></div><div style="clear:both;">主 题:Re: ForkJoinPool-3-worker pool size never size down</div><div style="clear:both;"><br /></div><head >
</head>
On 12/01/2024 12:29, 何品(虎鸣) wrote:<br >
<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 I know, it was suggested that not
pooling the <span >VirtualThread, when I replace my old
executors to use the fancy new
`VirtualThreadExecutorFactory` and with the </span></div>
<div style="clear:both;"><span ><span >`jdk.virtualThreadScheduler.maxPoolSize`
set to 2500</span></span></div>
<div style="clear:both;"><span ><span ><br >
</span></span></div>
<div style="clear:both;"><span ><span >after some load testing
and the thread size grow to <span >2205 </span></span></span></div>
<div style="clear:both;"><span ><span ><span ><br >
</span></span></span></div>
<div style="clear:both;">and even the stress testing is
removed from the system , the thread never adjust to a
smaller one. </div>
<br >
</div>
There are changes in JDK 22 [1] so that trimming happens a lot more
quickly when the pool is idle.<br >
<br >
-Alan<br >
<br >
[1] <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8319662" target="_blank">https://bugs.openjdk.org/browse/JDK-8319662</a><br >
</blockquote></div></div>