Skip to Content

Suggest JVM to Run Object Finalization Example

  1. /*
  2.         Suggest JVM to Run Object Finalization Example
  3.         This Java example shows how to suggest the JVM to run discarded
  4.         object's finalization methods.
  5.        
  6. */
  7.  
  8. public class RunFinalization {
  9.  
  10.         public static void main(String args[])
  11.         {
  12.                 /*
  13.                  * get current Java Runtime using getRuntime()
  14.                  * method of Runtime class.
  15.                  */
  16.                 Runtime runtime = Runtime.getRuntime();
  17.                
  18.                 /*
  19.                  * To suggest the JVM to run discarded object's finalization
  20.                  * methods, use
  21.                  *
  22.                  * void runFinalization()
  23.                  * method of Runtime class.
  24.                  *
  25.                  */
  26.                  
  27.                  runtime.runFinalization();
  28.         }
  29.        
  30. }