Home | History | Annotate | Download | only in src
      1 // Copyright 2007 The Android Open Source Project
      2 
      3 /**
      4  * Class with a bad finalizer.
      5  */
      6 public class BadFinalizer {
      7     public static void snooze(int ms) {
      8         try {
      9             Thread.sleep(ms);
     10         } catch (InterruptedException ie) {
     11             System.out.println("Snooze: " + ie.getMessage());
     12         }
     13     }
     14 
     15     protected void finalize() {
     16         System.out.println("Finalizer started and spinning...");
     17         int j = 0;
     18 
     19         /* spin for a bit */
     20         long start, end;
     21         start = System.nanoTime();
     22         for (int i = 0; i < 1000000; i++)
     23             j++;
     24         end = System.nanoTime();
     25         System.out.println("Finalizer done spinning.");
     26 
     27         System.out.println("Finalizer sleeping forever now.");
     28         while (true) {
     29             snooze(10000);
     30         }
     31     }
     32 }
     33 
     34