System.out.println("Finalizer timeout = "
+ VMRuntime.getRuntime().getFinalizerTimeoutMs() + " msecs."); // A separate method to ensure no dex register keeps the object alive.
createBadFinalizer(finalizerWait);
for (int i = 0; i < 2; i++) {
Runtime.getRuntime().gc();
}
// Now wait for the finalizer to start running. if (!finalizerWait.await(1, MINUTES)) {
System.out.println("finalizerWait timed out.");
}
// Sleep for less time than the default finalizer timeout, but significantly more than // the new timeout plus the 5 seconds we wait to dump thread stacks before actually // exiting.
snooze(9800); if (System.getenv("ART_TEST_ON_VM") != null) { // Under emulation we sometimes seem to just not shut down fast enough. If the process is // still running at this point, sleep again for longer. This makes the test much less // useful, but not 100% useless.
snooze(20_000);
}
// We should not get here, since it should only take 5.5 seconds for the timed out // finalizer to kill the process.
System.out.println("UNREACHABLE");
System.exit(0);
}
privatestaticvoid createBadFinalizer(CountDownLatch finalizerWait) {
BadFinalizer bf = new BadFinalizer(finalizerWait);
System.out.println("About to null reference.");
bf = null; // Not that this would make a difference, could be eliminated earlier.
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.