@backstreetbrogrammer
--------------------------------------------------------------------------------
Chapter 02 - Project Loom - Virtual Threads
--------------------------------------------------------------------------------
Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.
Goals
- Enable server applications written in the simple thread-per-request style to scale with near-optimal hardware utilization
- Enable existing code that uses the java.lang.Thread API to adopt virtual threads with minimal change
- Enable easy troubleshooting, debugging, and profiling of virtual threads with existing JDK tools
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.
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 are provided by the JDK rather than the OS and may be treated as user-mode threads.
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.
Virtual threads run by mounting an actual OS thread. When blocked, they unmount their OS thread, leaving it free to run the code of other virtual threads.
Github: github.com/backstreetbrogramm...
- Upgrade to Java 21 Playlist: • Upgrade to Java 21
- Apache Spark for Java Developers Playlist: • Apache Spark for Java ...
- Top Java Coding Interview Problems Playlist: • Top Java Coding Interv...
- Java Serialization Playlist: • Java Serialization
- Dynamic Programming Playlist: • Dynamic Programming
#java #javadevelopers #javaprogramming
Негізгі бет Ғылым және технология 05 - Project Loom - Virtual Threads
Пікірлер: 4