home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / lang / ref / PhantomReference.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  2.1 KB  |  69 lines

  1. /*
  2.  * @(#)PhantomReference.java    1.4 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang.ref;
  16.  
  17.  
  18. /**
  19.  * Phantom reference objects, for use in scheduling pre-mortem cleanup
  20.  * actions.
  21.  *
  22.  * <p> A <i>phantom</i> reference is a reference object that remains valid even
  23.  * after the collector determines that its referent may be reclaimed.  If a
  24.  * phantom reference is registered and the garbage collector determines at a
  25.  * certain point in time that its referent is no longer strongly reachable, has
  26.  * no guarded or weak references, and has been finalized, then at some later
  27.  * time the collector will enqueue the reference.
  28.  *
  29.  * <p> In order to ensure that a reclaimable object remains so, the referent of
  30.  * a phantom reference may not be retrieved: The <code>get</code> method of a
  31.  * phantom reference always returns <code>null</code>.
  32.  *
  33.  * @author Mark Reinhold
  34.  * @see java.lang.ref.Reference
  35.  * @since JDK1.2
  36.  */
  37.  
  38. public class PhantomReference extends Reference {
  39.  
  40.     /**
  41.      * Return <code>null</code>, since the referent of a phantom reference
  42.      * is always inaccessible.
  43.      */
  44.     public Object get() {
  45.     return null;
  46.     }
  47.  
  48.     /**
  49.      * Create a new phantom reference that refers to the given object.
  50.      * The new reference is not registered with any queue.
  51.      */
  52.     public PhantomReference(Object referent) {
  53.     super(referent);
  54.     }
  55.  
  56.     /**
  57.      * Create a new phantom reference that refers to the given object and
  58.      * is registered with the given queue.
  59.      *
  60.      * @exception  NullPointerException  If the <code>queue</code> argument
  61.      *                                   is <code>null</code>
  62.      */
  63.     public PhantomReference(Object referent, ReferenceQueue q) {
  64.     super(referent, q);
  65.     this.state = ACTIVE;
  66.     }
  67.  
  68. }
  69.