privatestaticfinallong ENQUEUE_TIMEOUT = 1000; // 1 sec, in millis
// P1 & P2 are PhantomReference objects // O1 & O2 are objects // // -> is a strong reference // => is a referent reference // // root -> P1 // root -> P2 // root -> O1 // root -> O2 // O1 -> O2 // P1 => O1 // P2 => O2 // // (1) Remove root -> O1 and collect. P1 notified, P2 !notified. // (2) Remove root -> O2 and collect. // // If phantom references are cleared when notified, as proposed by // 8071507, then P2 should be notified, and the test passes. // // Otherwise, P2 does not get notified because it remains reachable // from O1, which is being retained by P1. This fails the test.
privatestaticfinal ReferenceQueue<Object> Q1 = new ReferenceQueue<>(); privatestaticfinal ReferenceQueue<Object> Q2 = new ReferenceQueue<>();
privatestaticvolatile Object O2 = new Object(); privatestaticvolatile List<Object> O1 = new ArrayList<>(); static {
O1.add(O2);
}
privatestaticfinal PhantomReference<Object> P1 = new PhantomReference<>(O1, Q1); privatestaticfinal PhantomReference<Object> P2 = new PhantomReference<>(O2, Q2);
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.