原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/14988403.html

 

SRC

package org.fool.test;

import com.sun.management.OperatingSystemMXBean;

import java.lang.management.ManagementFactory;

public class TestJVM {
    public static void main(String[] args) {
        int byteToMB = 1024 * 1024;

        long totalMemory = Runtime.getRuntime().totalMemory() / byteToMB;
        long maxMemory = Runtime.getRuntime().maxMemory() / byteToMB;

        System.out.println("current init memory -Xms: " + totalMemory + " MB");
        System.out.println("current max memory -Xmx: " + maxMemory + " MB");

        OperatingSystemMXBean os = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        long freePhysicalMemory = os.getFreePhysicalMemorySize() / byteToMB;
        long totalPhysicalMemory = os.getTotalPhysicalMemorySize() / byteToMB;
        long usedPhysicalMemory = totalPhysicalMemory - freePhysicalMemory;

        System.out.println("os physical used memory: " + usedPhysicalMemory + " MB");
        System.out.println("os physical free memory: " + freePhysicalMemory + " MB");
        System.out.println("os physical total memory: " + totalPhysicalMemory + " MB");

        System.out.println("default heap init memory: physical memory size / 64 = " + totalPhysicalMemory / 64 + " MB");
        System.out.println("default heap max memory: physical memory size / 4 = " + totalPhysicalMemory / 4 + " MB");
    }
}

默认不设置任何参数运行(本机的内存大小是16G)

基于参数设置JVM内存空间

自定义设置VM Options

-Xms4096m -Xmx4096m

基于参数设置JVM内存空间

再次运行

基于参数设置JVM内存空间

 


欢迎点赞关注和收藏

基于参数设置JVM内存空间

 

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2021-04-23
  • 2021-04-24
猜你喜欢
  • 2021-12-06
  • 2021-03-31
  • 2021-11-11
  • 2021-11-07
相关资源
相似解决方案