This page tracks which blocking operations release the underlying thread to do other work. It's for reference purposes. Developers using the Java APIs should not be concerned with any of the details here, it's transparent and will be unspecified as to which APIs are scheduling points.
The following blocking operations are "virtual thread friendly". When not pinned, they will release the underlying carrier thread to do other work when the operation blocks.
API | Method(s) | Notes |
---|---|---|
java.lang.Thread | sleep, join | join to wait for a virtual thread to terminate |
java.lang.Process | waitFor | Linux/macOS only |
java.util.concurrent | All blocking operations | |
java.net.Socket | connect, read, write | Socket constructors with a host name parameter may need to do a lookup with InetAddress, see below |
java.net.ServerSocket | accept | |
java.net.DatagramSocket/MulticastSocket | receive | connect, disconnect and send do not block |
java.nio.channels.SocketChannel | connect, read, write | |
java.nio.channels.ServerSocketChannel | accept | |
java.nio.channels.DatagramChannel | read, receive | connect, disconnect, send, and write do not block |
java.nio.channels.Pipe.SourceChannel | read | |
java.nio.channels.Pipe.SinkChannel | write | |
Console streams (System.in, out, err) | read, write, printf | Linux/macOS only |
The following blocking operations use the ForkJoinPool.ManagedBlocker mechanism when invoked from a virtual thread. Parallelism is temporarily expanded until the blocking operation completes.
API | Method(s) | Notes |
---|---|---|
java.lang.Object | wait | |
java.lang.Process | waitFor | Windows only |
java.io.File | All file I/O operations | |
java.io.FileInputStream | open, read, skip | |
java.io.FileOutputStream | open, write | |
java.io.RandomAccessFile | open, read, write, seek | |
java.net.InetAddress | All lookup operations | InetAddress SPI in the works that will allow deploying a virtual thread friendly name resolver |
java.nio.MappedByteBuffer | force | |
java.nio.channels.Selector | All blocking selection operations | |
java.nio.channels.FileChannel | read, write, lock, truncate, force, transferTo | |
java.nio.file | All file I/O operations |
The following are some of the blocking operations that use the ForkJoinPool.ManagedBocker mechanism by way of the operations in the previous table.
API | Method(s) | Notes |
---|---|---|
java.lang.Thread | join | join to wait for a kernel thread to terminate |
java.lang.Process | All operations on the input/output/error streams | |
Console streams (System.in, out, err) | read, write, printf | Windows only |
java.io.Console | All read, format, printf operations |