JDK21 - Virtual Thread(虚拟线程)

2025/12/26

虚拟线程是 JVM 层面的用户态线程,上下文切换由 JVM 完成,避免了内核态和用户态的切换。

目标:方便写出 thread-per-request style 的代码。

下面是一些 https://openjdk.org/jeps/444 的摘抄。

A virtual thread is an instance of java.lang.Thread that is not tied to a particular OS thread. A platform thread, by contrast, is an instance of java.lang.Thread implemented in the traditional way, as a thin wrapper around an OS thread.

就像如果衣服极其便宜,我穿一件就扔一件,不需要保留。

img.png