Java Utililty Methods Memory Information

List of utility methods to do Memory Information

Description

The list of methods to do Memory Information are organized into topic(s).

Method

StringgetAviableMemoryAsString()
get Aviable Memory As String
long avaiableMemory = getAvaiableMemory();
double d = avaiableMemory / 1048576;
return (int) d + "MB";
longgetConsumedMemory(boolean preRunGarbageCollector)
get Consumed Memory
Runtime rt = getRuntimeAndRunGC(preRunGarbageCollector);
return bytesToMegabytes(rt.totalMemory() - rt.freeMemory());
chargetDenotationOfJVMMemorySettings(String stringMapJavaOpts)
get Denotation Of JVM Memory Settings
int index = -1;
if (stringMapJavaOpts.lastIndexOf('k') != -1) {
    return 'k';
} else if (stringMapJavaOpts.lastIndexOf('K') != -1) {
    return 'K';
} else if ((index = stringMapJavaOpts.lastIndexOf('m')) != -1 && index != 2) {
    return 'm';
} else if ((index = stringMapJavaOpts.lastIndexOf('M')) != -1) {
...
StringgetInMemoryURL(String dbName)
get In Memory URL
String url = IN_MEMORY_URL_PREFIX + dbName;
return url;
longgetJavaMemorySize(String string)
get Java Memory Size
String suffix = string.substring(string.length() - 1);
if (!suffix.matches(DIGITS_PATTERN)) {
    long value = Long.parseLong(string.substring(0, string.length() - 1));
    if (suffix.equalsIgnoreCase("k")) {
        value *= K;
    } else if (suffix.equalsIgnoreCase("m")) {
        value *= M;
    } else if (suffix.equalsIgnoreCase("g")) {
...
longgetJVMMemoryMB()
get JVM Memory MB
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / mb;
StringgetMemory()
get Memory
return tidyFileSize(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) + " / "
        + tidyFileSize(Runtime.getRuntime().totalMemory()) + " / "
        + tidyFileSize(Runtime.getRuntime().maxMemory());
longgetMemory()
get Memory
long used = 0;
for (int i = 0; i < 10; i++) {
    System.gc();
    long total = Runtime.getRuntime().totalMemory();
    long free = Runtime.getRuntime().freeMemory();
    used = total - free;
    if (used < MAX_MEMORY)
        return used;
...
longgetMemory(String memory)
get Memory
switch (memory.charAt(memory.length() - 1)) {
case 'k':
case 'K':
    return Long.parseLong(memory.substring(0, memory.length() - 1)) * 1000L;
case 'm':
case 'M':
    return Long.parseLong(memory.substring(0, memory.length() - 1)) * 1000000L;
case 'g':
...
longgetMemoryConsumedSincePreviousCall()
Returns amount of memory consumed since last call to getFreeMemory() (or this method)
long currentConsumption = runtime.freeMemory();
long consumed = currentConsumption - lastMemoryReading;
lastMemoryReading = currentConsumption;
return consumed;