Java Concurrency Interview

Virtual threads and structured concurrency question 113 of 180 mid

What is a virtual thread, and how is it scheduled?

A virtual thread is an ordinary java.lang.Thread whose execution is a continuation the JVM can park and resume. When it blocks, the JVM saves its stack to the heap, unmounts it from its carrier, and the carrier runs someone else. When the blocking call finishes, the continuation is mounted on any available carrier and resumed.

The scheduler is a dedicated ForkJoinPool in FIFO mode, sized to availableProcessors() by default. Creating one costs roughly a few hundred bytes rather than a megabyte of reserved stack, so millions are practical.

Everything else stays the same: Thread.currentThread(), thread dumps, try/catch, debuggers and stack traces all work, which is the entire point.

virtual-threads loom

Quiz yourself on Virtual threads and structured concurrency Suggest a correction