Get Free Memory of Java Virtual Machine(JVM) Example /*         Get Free Memory of Java Virtual Machine(JVM) Example    ...

Get Free Memory of Java Virtual Machine(JVM) Example

03:07 PASSOVE INCOME 0 Comments

Get Free Memory of Java Virtual Machine(JVM) Example

  1. /*
  2.         Get Free Memory of Java Virtual Machine(JVM) Example
  3.         This Java example shows how to get amount of free memory
  4.         in the Java Virtual Machine(JVM) using freeMemory method
  5.         of Java Runtime class.
  6. */
  7. public class GetFreeMemory {
  8.         public static void main(String args[])
  9.         {
  10.                 /*
  11.                  * get current Java Runtime using getRuntime()
  12.                  * method of Runtime class.
  13.                  */
  14.                 Runtime runtime = Runtime.getRuntime();
  15.                
  16.                 /*
  17.                  * To determine amount of free memory available to current
  18.                  * Java Virtual Machine(JVM), use
  19.                  *
  20.                  * long freeMemory()
  21.                  * method of Runtime class.
  22.                  */
  23.                  
  24.                  long freeMemory = runtime.freeMemory();
  25.                  
  26.                  System.out.println(freeMemory + " bytes free in JVM");
  27.         }
  28.        
  29.        
  30. }
  31. /*
  32. Typical output would be
  33. 4993048 bytes free in JVM
  34. *

0 comments: