Java / Java 21 Virtual Threads Interview questions
What are the types of threads available in Java 21?
Java 21 supports two kinds of java.lang.Thread: platform threads and virtual threads. Both share the same public API, but they behave very differently underneath.
| Platform Thread | Virtual Thread |
| Maps 1:1 to an OS thread. | Many virtual threads share a small pool of OS carrier threads. |
| Scheduled by the operating system. | Scheduled by the JVM's own scheduler. |
| Fixed, large stack (~1MB default). | Small, resizable stack stored on the heap. |
Platform threads suit CPU-bound or long-lived work; virtual threads suit high-volume, I/O-bound, short-lived tasks.
More Related questions...