The following blocking operations are virtual thread friendly; these methods "release" the underlying carrier thread 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.ManagedBocker mechanism when invoked from a virtual thread. Parallelism is temporarily extended 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 | |
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.io.Console | read, write, printf | Windows only |
java.lang.Process | All operations on the input/output/error streams |