Today, every instance of java.lang.Thread in the JDK is a platform thread. A platform thread runs Java code on an underlying OS thread and captures the OS thread for the code's entire lifetime. The number of platform threads is limited to the number of OS threads.总结下就是之前java中的线程是“platform thread”即平台线程,它由操作系统线程为基础,按照1:1的模式调度,这导致线程的创建与执行都是很耗资源的,同时数量也受系统的约束;但新的虚拟线程则是由JDK提供,你可以把它看作是在平台线程基础上创建的“一批”线程,它们有效地共享所属的平台线程也就是操作系统线程的资源,从而提升系统利用率,并不受数量限制。
A virtual thread is an instance of java.lang.Thread that runs Java code on an underlying OS thread but does not capture the OS thread for the code's entire lifetime. This means that many virtual threads can run their Java code on the same OS thread, effectively sharing it. While a platform thread monopolizes a precious OS thread, a virtual thread does not. The number of virtual threads can be much larger than the number of OS threads.
Virtual threads are a lightweight implementation of threads that is provided by the JDK rather than the OS. They are a form of user-mode threads, which have been successful in other multithreaded languages (e.g., goroutines in Go and processes in Erlang). User-mode threads even featured as so-called "green threads" in early versions of Java, when OS threads were not yet mature and widespread. However, Java's green threads all shared one OS thread (M:1 scheduling) and were eventually outperformed by platform threads, implemented as wrappers for OS threads (1:1 scheduling). Virtual threads employ M:N scheduling, where a large number (M) of virtual threads is scheduled to run on a smaller number (N) of OS threads.
1、Enable server applications written in the simple thread-per-request style to scale with near-optimal hardware utilization.说白了就是现在我们不用怎么改代码就可以创建一个轻量级的虚拟线程,实现简单同时还能够充分发挥硬件性能。
可以每个请求开启一个虚拟线程,实现简单直接的同时可以最大程度的提升硬件利用率;
2、Enable existing code that uses the java.lang.Thread API to adopt virtual threads with minimal change.
之前的多线程实现代码可以在较小的改动下完成向虚拟线程的迁移;
3、Enable easy troubleshooting, debugging, and profiling of virtual threads with existing JDK tools.
使用现有JDK工具可以完成虚拟线程的代码调试、分析与问题定位;
To ensure a smooth succession, we will initially make Generational ZGC available alongside non-generational ZGC. The -XX:+UseZGC command-line option will select non-generational ZGC; to select Generational ZGC, add the -XX:+ZGenerational option:使用命令行选项 -XX:+UseZGC 将选择非分代式 ZGC;要选择分代式 ZGC,需要添加 -XX:+ZGenerational 选项。
In a future release we intend to make Generational ZGC the default, at which point -XX:-ZGenerational will select non-generational ZGC. In an even later release we intend to remove non-generational ZGC, at which point the ZGenerational option will become obsolete.总结就是当前版本中如果想使用ZGC,命令行选项增加 -XX:+UseZGC,但默认是非分代式GC;要使用分代式ZGC ,需要改为 $ java -XX:+UseZGC -XX:+ZGenerational ,而在后续的版本中会默认改为分代GC。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |