--------
IntelliJ IDEA
配置参数:-Xms34m -Xmx234m
内存初始化大小,最小和最大值;
测试代码:
public class JVMDemoTest { public static void main(String[] args) { System.out.println("memory info : " + toMemoryInfo()); } static String toMemoryInfo() { Runtime runtime = Runtime.getRuntime(); int freeMemory = (int) (runtime.freeMemory() / 1024 / 1024); int totalMemory = (int) (runtime.totalMemory() / 1024 / 1024); return freeMemory + "M/" + totalMemory + "M(free/total)"; } }
配置参数后运行结果:
memory info : 32M/34M(free/total)
默认运行结果:
memory info : 254M/256M(free/total)