22 July 2010

Java: Get JVM Memory details



public class TestJVM {

public static void main(String args[]) {

Runtime r = Runtime.getRuntime();

// amount of unallocated memory
long free = r.freeMemory();

// total amount of memory available allocated and unallocated.
long total = r.totalMemory();

// total amount of allocated memory
long inuse = r.totalMemory() - r.freeMemory();

// max memory JVM will attempt to use
long max = r.maxMemory();
System.out.println("******************************************");
System.out.println("Java Virtual Machin SUMMARY ");
System.out.println("Total Memory : " + total/1024.00);
System.out.println("Free : " + free /1024.00);
System.out.println("inuse : " + inuse/1024.00 );
System.out.println("Available Processors: " + r.availableProcessors());
System.out.println("******************************************");
// suggest now would be a good time for garbage collection
System.gc();
}
}

No comments:

Post a Comment