Java Memory Used usedMemoryPercents()

Here you can find the source of usedMemoryPercents()

Description

Returns percents of used memory.

License

Open Source License

Declaration

public static double usedMemoryPercents() 

Method Source Code

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

public class Main {
    /**//from  w ww . j av  a  2 s.  co m
     * Returns percents of used memory.
     */
    public static double usedMemoryPercents() {
        Runtime runtime = Runtime.getRuntime();
        long totalMemory = runtime.totalMemory();
        return (double) (totalMemory - runtime.freeMemory()) / totalMemory
                * 100.0;
    }

    /**
     * Returns amount of total memory in bytes.
     */
    public static long totalMemory() {
        return Runtime.getRuntime().totalMemory();
    }

    /**
     * Returns amount of free memory in bytes.
     */
    public static long freeMemory() {
        return Runtime.getRuntime().freeMemory();
    }
}

Related

  1. usedMemory()
  2. usedMemory(Runtime runtime)
  3. usedMemoryAsString()
  4. usedMemorym()
  5. usedMemoryMB()
  6. usedMemoryRatio()
  7. useMemoryLimitOver()