回复:Virtual thread hang and all threads stop running on JDK21
何品(虎鸣)
hepin.p at alibaba-inc.com
Tue Jun 4 13:32:25 UTC 2024
eg: the code below, seems like the VM is corrupted
private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
128,
128,
60,
TimeUnit.SECONDS,
new LinkedBlockingDeque<>(),
new NamedThreadFactory("OrderedTaskRunnerCarrier"));
static {
EXECUTOR.prestartAllCoreThreads();
}
private static final Executor VTExecutor = VirtualThreadSupport.virtualize(
"OrderedTaskRunner",
false,
EXECUTOR);
------------------------------------------------------------------
发件人:何品(虎鸣) <hepin.p at alibaba-inc.com>
发送时间:2024年6月4日(星期二) 21:29
收件人:loom-dev <loom-dev at openjdk.org>
主 题:Virtual thread hang and all threads stop running on JDK21
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。
```java
public static Executor virtualize(final String prefix,
final boolean enabled,
final Executor executor) {
if (!enabled) {
return executor;
}
try {
final var builder = Thread.ofVirtual();
if (executor != null) {
final var clazz = builder.getClass();
final var privateLookup = MethodHandles.privateLookupIn(clazz, lookup);
final var schedulerFieldSetter = privateLookup.findSetter(clazz, "scheduler", Executor.class);
schedulerFieldSetter.invoke(builder, executor);
}
builder.name(prefix + "-virtual-thread-", 0L);
final var factory = builder.factory();
return Executors.newThreadPerTaskExecutor(factory);
} catch (Throwable e) {
log.error("Error when virtualize a executor", e);
return executor;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20240604/89c7d7b8/attachment-0001.htm>
More information about the loom-dev
mailing list