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.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 | socket adaptor connect, read, and write also okay |
java.nio.channels.ServerSocketChannel | accept | socket adaptor accept also okay |
java.nio.channels.DatagramChannel | read, receive | socket adaptor receive also okay |
java.nio.channels.Pipe.SourceChannel | read | |
java.nio.channels.Pipe.SinkChannel | write | |
Console streams (System.in, out, err) | read, write, printf | Linux/macOS only at this time. |
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) |
---|---|
java.lang.Object | wait |
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 blocking operations use the ForkJoinPool.ManagedBocker mechanism by way of 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 | input/output/error streams |