Usage:
This flag allows you to set a maximum size of New Input/Output (NIO) direct cache. Its syntax is: -XX:MaxDirectMemorySize=size, where size is the size in bytes.
Since:
Starting from JDK 6.
Examples:
To enable summary mode for Native Memory Tracking:
java -XX:MaxDirectMemorySize=summary MainClass
Description:
Java provides a new I/O system called NIO (New I/O). NIO provides a different way of handling I/O than the standard I/O API. It is Java's replacement for the traditional I/O API (since Java 1.4).
It supports buffer-oriented, channel-based I/O operation methods. With the introduction of JDK 7, the NIO system has been extended with enhanced support for file system functions and file handling. Because of these new features supported by the NIO file class, NIO is widely used in file processing.
NIO implements high-speed I/O for Java programmers without using custom native code. NIO moves the temporal I/O activity of filling, draining buffers, etc. back to the operating system, greatly speeding up operations.
- Channels and Buffers: In the standard I/O API, character streams and byte streams are used. In NIO, channels and buffers are used. Data is always written to the channel from the buffer, and read from the channel to the buffer.
- Selectors (Selectors): Java NIO provides the concept of "selectors". This is an object that can be used to monitor multiple channels, such as data arrival, connection open, etc. Therefore, a single thread can monitor data in multiple channels.
- Non-blocking I/O (Non-blocking I/O): Java NIO provides the function of non-blocking I/O. This application returns any available data immediately and the application should have a pooling mechanism to find out if more data is ready.
The flag “-XX:MaxDirectMemorySize” is used to set “java.nio” the maximum size of New Input/Output (NIO) direct-buffer allocations. The default value is 0, which means that the JVM itself automatically chooses the maximum size for NIO direct-buffer allocations.
You can also specify a data unit such as “k” or “K” for kilobytes, “m” or “M” for Megabytes and “g” or “G” for Gigabytes.
- For using 512 Kilobytes: -XX:MaxDirectMemorySize=512k
- For using 128 Megabytes: -XX:MaxDirectMemorySize=128m
- For using 12 Gigabytes: -XX:MaxDirectMemorySize=12g
Default Value:
The default size is 0.
Related Posts:
- Non-blocking I/O (Java)
- Analysis of Java NIO
- Java Oracle
Edit your Comment