blockFinalizerThread looks buggy to me. 103 private static void blockFinalizerThread() throws InterruptedException { 104 System.out.println("trying to block the finalizer thread"); 105 o1 = new MyObject(); 106 o1 = null; 107 System.gc(); 108 System.runFinalization(); 109 finRunLatch.await(); 110 }
Why are you calling System.runFinalization() ? You are trying to block the primary finalizer thread; you definitely don't want the object to be handled by the secondary finalizer thread. --- 51 } else { 52 System.out.println("finalizing the test instance"); I would check : else if (Thread.currentThread().getName().equals("Secondary finalizer")) { .... else fail(unexpected finalizer thread name)