Java Memory Information getMemoryConsumedSincePreviousCall()

Here you can find the source of getMemoryConsumedSincePreviousCall()

Description

Returns amount of memory consumed since last call to getFreeMemory() (or this method)

License

Open Source License

Return

long

Declaration

public static long getMemoryConsumedSincePreviousCall() 

Method Source Code

//package com.java2s;
/*//from w w w .  j av a2s  .  co m
 * $Id$
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

public class Main {
    private static Runtime runtime = Runtime.getRuntime();
    private static long lastMemoryReading = 0;

    /**
     * Returns amount of memory consumed since last call to getFreeMemory() (or this method)
     * @return long 
     */
    public static long getMemoryConsumedSincePreviousCall() {
        long currentConsumption = runtime.freeMemory();
        long consumed = currentConsumption - lastMemoryReading;

        // Update in case user wants to make repeated calls to this method only
        lastMemoryReading = currentConsumption;

        return consumed;
    }
}

Related

  1. getJavaMemorySize(String string)
  2. getJVMMemoryMB()
  3. getMemory()
  4. getMemory()
  5. getMemory(String memory)
  6. getMemoryIncrease()
  7. getMemoryInfo()
  8. getMemoryLimit()
  9. getMemoryLimitMinSize()