Sobes.tech
Junior — Middle

What new solution for thread management was introduced in Java 21?

sobes.tech AI

Answer from AI

In Java 21, a new solution for thread management was introduced — Virtual Threads. These are lightweight threads that significantly simplify the development of high-performance multithreaded applications. Virtual threads allow creating thousands or even millions of threads with minimal resource consumption, unlike traditional platform threads.

Example of creating a virtual thread:

Thread.startVirtualThread(() -> {
    System.out.println("Virtual thread is running");
});

This solution improves scalability and simplifies asynchronous programming, enabling code to be written in a synchronous style without blocking.