skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Tuesday, October 16, 2012

Compute Heap Memory Statistics using Java Runtime Class

Posted by Raju Gupta at 6:00 AM – 0 comments
 
This Java Program will compute the maximum Heap memory, available Heap Memory and Used Memory statistics.

public class HeapStatMemory {
 public static void main(String[] args) {
  int mb = 1024 * 1024;
  Runtime runtime = Runtime.getRuntime();
  System.out
    .println("**********Heap Memory statistics [MB]**************");
  // Compute and print used memory
  System.out.println("Used Memory:"
    + (runtime.totalMemory() - runtime.freeMemory()) / mb);
  // Compute and Print free memory
  System.out.println("Free Memory:" + runtime.freeMemory() / mb);
  // Compute and Print total available memory
  System.out.println("Total Memory:" + runtime.totalMemory() / mb);
  // Compute and Print Maximum available memory
  System.out.println("Max Memory:" + runtime.maxMemory() / mb);
  System.out
    .println("***************************************************");
 }
}


Labels: Java Runtime Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger