Home | History | Annotate | Download | only in base
      1 /*
      2  * Copyright (C) 2007 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.base;
     18 
     19 import java.lang.ref.PhantomReference;
     20 
     21 /**
     22  * Phantom reference with a {@code finalizeReferent()} method which a
     23  * background thread invokes after the garbage collector reclaims the
     24  * referent. This is a simpler alternative to using a {@link
     25  * java.lang.ref.ReferenceQueue}.
     26  *
     27  * <p>Unlike a normal phantom reference, this reference will be cleared
     28  * automatically.
     29  *
     30  * @author Bob Lee
     31  * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library)
     32  */
     33 public abstract class FinalizablePhantomReference<T>
     34     extends PhantomReference<T> implements FinalizableReference {
     35 
     36   /**
     37    * Constructs a new finalizable phantom reference.
     38    *
     39    * @param referent to phantom reference
     40    * @param queue that should finalize the referent
     41    */
     42   protected FinalizablePhantomReference(T referent,
     43       FinalizableReferenceQueue queue) {
     44     super(referent, queue.queue);
     45     queue.cleanUp();
     46   }
     47 }
     48