前言
JDK21
之后,提供了创建并启动虚拟线程的便捷方式
创建虚拟线程
JDK21
之后,提供了Thread.startVirtualThread
方法快速创建虚拟线程
arduino
public class VirThreadDemo {
public static void main(String[] args) throws InterruptedException {
Thread thread = Thread.startVirtualThread(() -> {
System.out.println("虚拟线程创建=============");
});
thread.join();
}
}
输出结果为

总结
JDK21
中最终确定虚拟线程,可以使用它快速创建并启动虚拟线程