Example usage for java.lang Runtime freeMemory

List of usage examples for java.lang Runtime freeMemory

Introduction

In this page you can find the example usage for java.lang Runtime freeMemory.

Prototype

public native long freeMemory();

Source Link

Document

Returns the amount of free memory in the Java Virtual Machine.

Usage

From source file:org.codelibs.fess.util.MemoryUtil.java

public static String getMemoryUsageLog() {
    final Runtime runtime = Runtime.getRuntime();
    final long freeBytes = runtime.freeMemory();
    final long maxBytes = runtime.maxMemory();
    final long totalBytes = runtime.totalMemory();
    final long usedBytes = totalBytes - freeBytes;
    return "Mem:{used " + byteCountToDisplaySize(usedBytes) + ", heap " + byteCountToDisplaySize(totalBytes)
            + ", max " + byteCountToDisplaySize(maxBytes) + "}";
}

From source file:Mem.java

public static long used() {
    Runtime r = Runtime.getRuntime();
    return r.totalMemory() - r.freeMemory();
}

From source file:Main.java

public static long availableMemory() {
    final Runtime runtime = Runtime.getRuntime();
    final long used = runtime.totalMemory() - runtime.freeMemory();

    final ActivityManager activityManager = (ActivityManager) sContext
            .getSystemService(Context.ACTIVITY_SERVICE);
    final long total = activityManager.getMemoryClass() * 1024 * 1024;

    return total - used;
}

From source file:com.talis.entity.TestUtils.java

public static void showMemory() {
    Runtime r = Runtime.getRuntime();
    long bytes = r.totalMemory() - r.freeMemory();
    System.out.println(String.format("Memory usage : %s (%s)", FileUtils.byteCountToDisplaySize(bytes), bytes));
}

From source file:MemoryUtils.java

static double usedMemory(Runtime runtime) {
    long totalMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();
    double usedMemory = (double) (totalMemory - freeMemory) / (double) (1024 * 1024);
    return usedMemory;
}

From source file:com.bstek.dorado.console.utils.SystemUtils.java

/**
 * ??//from  w w w  .  j  a va  2s .c o  m
 * 
 * @return
 */
public static Map<String, Object> getMemoryInfo() {
    Map<String, Object> map = new HashMap<String, Object>();
    Runtime runtime = Runtime.getRuntime();
    map.put("runtime", runtime);

    map.put("freeMemory", runtime.freeMemory());
    map.put("totalMemory", runtime.totalMemory());
    if (System.getProperty("java.version").compareTo("1.4") >= 0)
        map.put("maxMemory", runtime.maxMemory());
    else
        map.put("maxMemory", "N/A");

    map.put("CPU", runtime.availableProcessors());
    return map;
}

From source file:ee.ria.xroad.proxy.opmonitoring.OpMonitoringBufferMemoryUsage.java

private static long getUsedBytes(Runtime runtime) {
    return runtime.totalMemory() - runtime.freeMemory();
}

From source file:net.ymate.platform.commons.util.RuntimeUtils.java

/**
 * /*from   w  w w .j  a va 2  s  .  c  o m*/
 *
 * @return ??
 */
public static final long gc() {
    Runtime rt = Runtime.getRuntime();
    long lastUsed = rt.totalMemory() - rt.freeMemory();
    rt.gc();
    return lastUsed - rt.totalMemory() + rt.freeMemory();
}

From source file:net.nosleep.superanalyzer.util.Misc.java

public static void printMemoryInfo(String tag) {
    Runtime rt = Runtime.getRuntime();
    long free = rt.freeMemory();
    long total = rt.totalMemory();
    long max = rt.maxMemory();

    System.out.println("Memory (" + tag + "): " + free + "/" + total + " (max " + max + ")");
}

From source file:ninja.undertow.Benchmarker.java

static public void logMemory() {
    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    log.info("##### Heap utilization statistics [MB] #####");

    //Print used memory
    log.info("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()));

    //Print free memory
    log.info("Free Memory:" + runtime.freeMemory());

    //Print total available memory
    log.info("Total Memory:" + runtime.totalMemory());

    //Print Maximum available memory
    log.info("Max Memory:" + runtime.maxMemory());
}