how to check my java heap space size

how to check my java heap space size

To check the Java heap space size in your application, you can use the getRuntime method of the Runtime class to get the current Java runtime and then use the maxMemory method to get the maximum amount of memory that the Java virtual machine will attempt to use.

Here's an example of how you might do this:

public class Main {
    public static void main(String[] args) {
        long heapSpaceSize = Runtime.getRuntime().maxMemory();
        System.out.println("Heap space size: " + heapSpaceSize + " bytes");
    }
}
Source:ww‮ruttual.w‬i.com

In this example, the maxMemory method is used to get the maximum amount of memory that the Java virtual machine will attempt to use, and this value is printed to the console.

Note that the actual heap space size may be smaller than the maximum heap space size, depending on the availability of system resources.

Created Time:2017-11-01 12:05:13  Author:lautturi