< prev index next >

src/java.base/share/classes/java/lang/ref/Reference.java

Print this page

313             public void startThreads() {
314                 ThreadGroup tg = Thread.currentThread().getThreadGroup();
315                 for (ThreadGroup tgn = tg;
316                      tgn != null;
317                      tg = tgn, tgn = tg.getParent());
318                 Reference.startReferenceHandlerThread(tg);
319                 Finalizer.startFinalizerThread(tg);
320             }
321 
322             @Override
323             public boolean waitForReferenceProcessing()
324                 throws InterruptedException
325             {
326                 return Reference.waitForReferenceProcessing();
327             }
328 
329             @Override
330             public void runFinalization() {
331                 Finalizer.runFinalization();
332             }
333 
334             @Override
335             public <T> ReferenceQueue<T> newNativeReferenceQueue() {
336                 return new NativeReferenceQueue<T>();
337             }
338         });
339     }
340 
341     /* -- Referent accessor and setters -- */
342 
343     /**
344      * Returns this reference object's referent.  If this reference object has
345      * been cleared, either by the program or by the garbage collector, then
346      * this method returns {@code null}.
347      *
348      * @apiNote
349      * This method returns a strong reference to the referent. This may cause
350      * the garbage collector to treat it as strongly reachable until some later
351      * collection cycle.  The {@link #refersTo(Object) refersTo} method can be
352      * used to avoid such strengthening when testing whether some object is
353      * the referent of a reference object; that is, use {@code ref.refersTo(obj)}
354      * rather than {@code ref.get() == obj}.
355      *
356      * @return   The object to which this reference refers, or
357      *           {@code null} if this reference object has been cleared

313             public void startThreads() {
314                 ThreadGroup tg = Thread.currentThread().getThreadGroup();
315                 for (ThreadGroup tgn = tg;
316                      tgn != null;
317                      tg = tgn, tgn = tg.getParent());
318                 Reference.startReferenceHandlerThread(tg);
319                 Finalizer.startFinalizerThread(tg);
320             }
321 
322             @Override
323             public boolean waitForReferenceProcessing()
324                 throws InterruptedException
325             {
326                 return Reference.waitForReferenceProcessing();
327             }
328 
329             @Override
330             public void runFinalization() {
331                 Finalizer.runFinalization();
332             }





333         });
334     }
335 
336     /* -- Referent accessor and setters -- */
337 
338     /**
339      * Returns this reference object's referent.  If this reference object has
340      * been cleared, either by the program or by the garbage collector, then
341      * this method returns {@code null}.
342      *
343      * @apiNote
344      * This method returns a strong reference to the referent. This may cause
345      * the garbage collector to treat it as strongly reachable until some later
346      * collection cycle.  The {@link #refersTo(Object) refersTo} method can be
347      * used to avoid such strengthening when testing whether some object is
348      * the referent of a reference object; that is, use {@code ref.refersTo(obj)}
349      * rather than {@code ref.get() == obj}.
350      *
351      * @return   The object to which this reference refers, or
352      *           {@code null} if this reference object has been cleared
< prev index next >