Java examples for java.lang.management:MemoryMXBean
log Heap Status
//package com.java2s; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; public class Main { public static final long MEGABYTE = 1048576; public static void logHeapStatus() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); System.out.println(String .format("Heap: %sM used, %sM commited, %sM max", memoryMXBean.getHeapMemoryUsage().getUsed() / MEGABYTE, memoryMXBean .getHeapMemoryUsage().getCommitted() / MEGABYTE, memoryMXBean .getHeapMemoryUsage().getMax() / MEGABYTE)); }/*w w w .j av a2s . c o m*/ }