Performance Issues with Virtual Threads + ThreadLocal Caching in Third-Party Libraries (JDK 25)
Alan Bateman
alan.bateman at oracle.com
Sat Jan 24 16:41:26 UTC 2026
On 24/01/2026 13:07, Jianbin Chen wrote:
> Hi Alan,
>
> I ran my example on JDK 21 because it uses Thread.sleep. In an earlier
> message on the mailing list I learned that virtual‑thread performance
> on JDK 25 was worse for this kind of scenario compared with JDK 21,
> and that the issue is supposed to be fixed in JDK 25.0.3 — which has
> not been released yet.
I assume this is about JDK-8370887 [1], which may be an issue in some
usages but I don't think has come up in this thread. For your
Thread.sleep benchmark then maybe you can try it with the JDK 26 EA
builds [2] where you know that issue has been fixed. As I said, I think
that benchmark will need a bit of work (esp. on warmup) to get useful data.
>
> That said, this does not affect the main point of my message: I’m
> asking for advice about using pooled virtual threads to work around
> third‑party libraries that implement buffer pools via ThreadLocal
The advise is to not pool virtual threads. If a library is performing
poorly because it assumes execution on a pooled thread then all we can
suggest is to work with the maintainer of that library on the issue.
Note that the JDK removed several usages of thread locals that were
caching byte[] and other objects. That caching was beneficial a long
time ago but not in recent recent/releases with significantly improved
memory management and GC.
-Alan
[1] https://bugs.openjdk.org/browse/JDK-8370887
[2] https://jdk.java.net/26/
More information about the loom-dev
mailing list