Virtual thread hang and all threads stop running on JDK21
robert engels
rengels at ix.netcom.com
Tue Jun 4 13:44:37 UTC 2024
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.
> On Jun 4, 2024, at 8:29 AM, 何品(虎鸣) <hepin.p at alibaba-inc.com> 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。
>
>
>
> ```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/24adb6e5/attachment.htm>
More information about the loom-dev
mailing list