Finalizer started and spinning...
Finalizer done spinning.
Finalizer sleeping forever now.
-Caught exception: Main$BadFinalizer.finalize() timed out after 10 seconds
public static void main(String[] args) {
BadFinalizer bf = new BadFinalizer();
- Thread.setDefaultUncaughtExceptionHandler(
- new Thread.UncaughtExceptionHandler() {
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- System.out.println("Caught exception: " + e.getMessage());
- System.exit(0);
- }
- });
-
System.out.println("About to null reference and request GC.");
bf = null;
Runtime.getRuntime().gc();
In finalizer
-Caught exception: whee
+done
}
public static void main(String[] args) {
- Thread.setDefaultUncaughtExceptionHandler(
- new Thread.UncaughtExceptionHandler() {
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- System.out.println("Caught exception: " + e.getMessage());
- }
- });
-
createAndForget();
System.gc();
} catch (InterruptedException ie) {
System.err.println(ie);
}
+
+ System.out.println("done");
}
protected void finalize() throws Throwable {