public void testSystemRunFinalizationReturnsEvenIfQueueIsNonEmpty() throws Exception {
  AtomicInteger count=new AtomicInteger();
  AtomicBoolean keepGoing=new AtomicBoolean(true);
  createChainedFinalizer(count,keepGoing);
  while (count.get() == 0) {
    Thread.sleep(500);
    FinalizationTester.induceFinalization();
  }
  keepGoing.set(false);
  assertTrue(count.get() > 0);
}

public void testSystemRunFinalizationReturnsEvenIfQueueIsNonEmpty ( ) throws Exception { AtomicInteger count = new AtomicInteger ( ) ; AtomicBoolean keepGoing = new AtomicBoolean ( true ) ; createChainedFinalizer ( count , keepGoing ) ; while ( count . get ( ) == 0 ) { Thread . sleep ( 500 ) ; FinalizationTester . induceFinalization ( ) ; } keepGoing . set ( false ) ; assertTrue ( count . get ( ) > 0 ) ; }
make sure that system . runfinalization ( ) returns even if the finalization queue is never completely empty . http : / / b / 4193517
