Java Memory Information getMemoryUtilizationPercent()

Here you can find the source of getMemoryUtilizationPercent()

Description

Get the amount of memory used by the current JVM as a percentage of the maximum amount of memory it is allowed to use (via the -Xmx parameter)

License

Open Source License

Return

Memory utilization as a number between 0.0 and 1.0.

Declaration

public static float getMemoryUtilizationPercent() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  w  w w . ja v a  2s.c  om*/
     * Get the amount of memory used by the current JVM as a percentage of the maximum amount of
     * memory it is allowed to use (via the <code>-Xmx</code> parameter)
     * 
     * @return Memory utilization as a number between <code>0.0</code> and <code>1.0</code>.
     */
    public static float getMemoryUtilizationPercent() {
        final Runtime rt = Runtime.getRuntime();
        final float usedMemory = rt.totalMemory() - rt.freeMemory();
        return usedMemory / rt.maxMemory();
    }
}

Related

  1. getMemoryStats()
  2. getMemoryStats(int mode)
  3. getMemoryStatus(boolean preRunGarbageCollector)
  4. getMemoryString()
  5. getMemoryString()
  6. getNowMemoryStatus()
  7. getRuntimeMemoryStats()
  8. getRuntimeMemoryStats()
  9. getSummaryMemoryReportHeader()