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

    再次运行


    欢迎点赞关注和转发

    强者自救 圣者渡人
  • 相关阅读:
    Uva 11991 Easy Prblem from Rujia Liu ?
    BANK && IT
    随机数发生器(对拍)-----对比测试
    HDU 1695(GCD)
    欧拉定理与费马定理,离散对数定理
    POJ 2352 (stars)
    线段树
    codeforces 51C(Three Base Stations)
    codeforces 165B(Burning Midnight Oil)
    POJ 2785(4 Values whose Sum is 0)
  • 原文地址:https://www.cnblogs.com/agilestyle/p/14988403.html
Copyright © 2011-2022 走看看