zoukankan      html  css  js  c++  java
  • 基于参数设置JVM内存空间

    原创转载请注明出处: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)

    自定义设置VM Options

    -Xms4096m -Xmx4096m

    再次运行


    欢迎点赞关注和转发

    强者自救 圣者渡人
  • 相关阅读:
    感知机学习笔记
    NOIP 模拟19
    NOIP 模拟17
    NOIP模拟14-16
    「动态规划」-数位dp专题
    8.5 NOIP 模拟测试 13
    8.3 NOIP 模拟12题解
    8.3 NOIP CE反思
    「分治」-cdq分治
    8.1 NOIP模拟11
  • 原文地址:https://www.cnblogs.com/agilestyle/p/14988403.html
Copyright © 2011-2022 走看看