回复:Virtual thread hang and all threads stop running on JDK21
何品(虎鸣)
hepin.p at alibaba-inc.com
Wed Jun 5 09:47:59 UTC 2024
> I am surprised that anything works at all. You may have success if you make your executor create instances of CarrierThread - which is public.
Thanks, but the `CarrierThread` needs a ForkJoinPool, but I'm using TheadPoolExecutor, have to adapt that.
------------------------------------------------------------------
发件人:何品(虎鸣) <hepin.p at alibaba-inc.com>
发送时间:2024年6月5日(星期三) 17:37
收件人:Alan Bateman<Alan.Bateman at oracle.com>; "何品(虎鸣)"<hepin.p at alibaba-inc.com>; "loom-dev"<loom-dev at openjdk.org>
主 题:回复:Virtual thread hang and all threads stop running on JDK21
Thanks,
1. it hung when we are sharing the common usage of the Virtualthread (the default scheduler) cross two modules.
2. after that, I try to hack the virtual thread builder with separated ThreadPoolExecutor.
3. but still , it hung.
when it hung, `jcmd Thread.print` prints nothing. and dump programly print nothing too.
After switch back to normal thread, it never hang.
Some information:
module A is using `Object.notifyAll, Object.wait` and module B is using `CompletableFuture.get` (may > 100 times in one rune)
I was thinking if that could be a problem of notification missing, where in Module A, the concurrency is 3000, protected by a semaphore, but the underling Carrier Thread is only 128, and 3000 > 128.
public void init() {
// 监控线程
VTExecutor.execute(() -> {
for (; ; ) {
try {
Thread.sleep(IDLE_SLEEP_TIME);
} catch (InterruptedException e) {
// ignore
}
log.info(
"BlockableVirtualThreadExecutor completed tasks:[{}] inflight tasks:[{}] semaphore available permits: [{}]",
completedTaskCounter.get(),
inflightTaskCounter.get(),
semaphore.availablePermits());
}
});
}
When it hung, this code will never prints any more.
public static void jstack(OutputStream stream) throws Exception {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
long[] allThreadIds = threadMXBean.getAllThreadIds();
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(allThreadIds, true, true);
for (ThreadInfo threadInfo : threadInfos) {
if (threadInfo != null) {
stream.write(printThreadInfoDepth(threadInfo, 1000).getBytes());
}
}
}
------------------------------------------------------------------
发件人:Alan Bateman <Alan.Bateman at oracle.com>
发送时间:2024年6月4日(星期二) 21:45
收件人:"何品(虎鸣)"<hepin.p at alibaba-inc.com>; "loom-dev"<loom-dev at openjdk.org>
主 题:Re: Virtual thread hang and all threads stop running on JDK21
On 04/06/2024 14:29, 何品(虎鸣) wrote:
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.
We try to separate the Virtual Thread's scheduler with reflections. but that does not work too.
Our userbase are pretty simple:
A: VT Executor backing by 128-sized ThreadPoolExecutor for running java code with `CompletableFuture.get`
B: VT Executor backing by 64-sized ThreadPoolExecutor for retrieving data with HTTP client, with max concurrency to 3000 (virtual threads)
Even if A and B are using Different backing ThreadPool, they all stop responding。
There isn't much to go on here. There isn't any support at this time for custom schedulers so I can't tell if the hang is when you use the default scheduler or only when you use reflection to hack in and set your own?
Also when you say "thread dump", do you mean the HotSpot VM thread dump (ctrl-\, jstack, jcmd Thread.print) or do you mean the thread dump that prints all virtual threads (jcmd Thread.dump_to_file)?
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20240605/156596af/attachment-0001.htm>
More information about the loom-dev
mailing list