jmap can know size of each generation, but I want to monitor my java process real time.
With jmx, MemoryMXBean.getHeapMemoryUsage().getUsed()
can get the total heap size. But I cannot find any method to get:
You can use ManagementFactory.getMemoryPoolMXBeans()
. It shows all the memory regions. Depending on the GC you used, the names differ. pool.getCollectionUsage().getInit()
gives the initial size of a pool. pool.getName()
is for example 'G1 Eden Space' or 'G1 Old Gen' or 'G1 Survivor Space' if you use G1 GC.
pool.getUsage().getUsed()
returns as well the amount of used memory for that region.