Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Everything You Need to Know about Virtual Threads in Java

--

Virtual Threads was introduced as a Preview Feature in Java 19 and finally standardized in Java 21. Understanding this feature is necessary for a backend developer working to improve system performance and working with throughput systems.

Virtual threads are decoupled from the hardware, so it does not rely on OS threads during its cycle of operation.

Virtual Threads introduces a lightweight threading model that handles high throughput with minimum resource consumption.

Virtual Threads are instances of standard java.lang.Thread class.

My articles are free for everyone. Non-members can read this full article for free HERE.

What are Virtual Threads?

Virtual Threads are lightweight threads managed by a Java Virtual Machine.

They are much better than platform threads, which often require more memory.

  • Platform threads are more resource-intensive.
  • Operating System limits them. Number of threads that can be created is limited.
  • Content switching is expensive for platform threads.
// Creating a single virtual thread
Thread vThread = Thread.ofVirtual().start(() -> {…
Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Saquib Aftab
Saquib Aftab

Written by Saquib Aftab

Lead Software Engineer | Java | Technology | Productivity | Learning and Improving to become a better developer

Responses (3)