Whenever a virtual thread is started, the JVM will mount it on an OS thread. As soon as the virtual thread runs into a blocking operation like an
HTTP request or a filesystem read/write operation, the JVM will detect this and unmount the virtual thread. This allows another virtual thread to take
over the OS thread and continue its execution.
This is why virtual threads should be preferred to platform threads for tasks that involve blocking operations. By default, a Java thread is a
platform thread. To use a virtual thread it must be started either with Thread.startVirtualThread(Runnable)
or
Thread.ofVirtual().start(Runnable)
.
This rule raises an issue when a platform thread is created with a task that includes heavy blocking operations.