Monday, September 2, 2013

Get runtime memory with Java code

To get total memory, maximum memory and free memory in Java Virtual Machine using Java code.

Get runtime memory with Java code
Get runtime memory with Java code


package java_runtimememory;

/**
*
* @web http://java-buddy.blogspot.com/
*/
public class Java_RuntimeMemory {

public static void main(String[] args) {
System.out.println(Runtime.getRuntime().toString() + "\n");

System.out.println("totalMemory: the total amount of memory in the Java "
+ "virtual machine.\n"
+ Runtime.getRuntime().totalMemory());

System.out.println("maxMemory: the maximum amount of memory that the "
+ "Java virtual machine will attempt to use.\n"
+ Runtime.getRuntime().maxMemory());

System.out.println("freeMemory: the amount of free memory in the Java "
+ "Virtual Machine.\n"
+ Runtime.getRuntime().freeMemory());
}
}


Related: Set memory option for JVM

No comments:

Post a Comment