unix_junkie

FinalizerTest.java

Jul 3rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.48 KB | None | 0 0
  1. class FinalizerTest {
  2.     private static volatile FinalizerTest sharedInstance;
  3.  
  4.     @Override
  5.     protected void finalize() throws Throwable {
  6.         sharedInstance = this;
  7.     }
  8.  
  9.     public static void main(final String args[]) {
  10.         int value = 0;
  11.         for (int i = 0; i < 1; i++) {
  12.             final FinalizerTest instance = new FinalizerTest();
  13.             value ^= instance.hashCode();
  14.         }
  15.  
  16.         for (int i = 0; i < 20; i++) {
  17.             System.gc();
  18.         }
  19.  
  20.         System.out.println(sharedInstance);
  21.         System.exit(value);
  22.     }
  23. }
Add Comment
Please, Sign In to add comment