Java.lang.System.runFinalization() Method

Advertisements


Description

The java.lang.System.runFinalization() method runs the finalization methods of any objects pending finalization.

Declaration

Following is the declaration for java.lang.System.runFinalization() method

public static void runFinalization()

Parameters

  • NA

Return Value

This method does not return any value.

Exception

  • NA

Example

The following example shows the usage of java.lang.System.runFinalization() method.

package com.tutorialspoint;

import java.lang.*;

public class SystemDemo {

   public static void main(String[] args) throws Exception {

     File file1 = new File("abcd");
   
     // returns the HashCode
     int ret = System.identityHashCode(file1);
     System.out.println(ret);
   
     // returns the current value of the system timer, in milliseconds
     System.out.print("time in milliseconds = ");
     System.out.println(System.currentTimeMillis());
    
     System.out.println("finalization of any objects pending finalization!");
     System.runFinalization();
     System.out.println("Done!!!");    
   }
} 

Let us compile and run the above program, this will produce the following result:

355165777
time in milliseconds = 1350971291853
finalization of any objects pending finalization!
Done!!!



Advertisements
Advertisements