blob: 39d3570b7e8e94ad6bda41b58af5ae277c78face [file] [log] [blame]
crazyboblee210bf432009-02-05 06:04:18 +00001/*
2 * Copyright (C) 2007 Google Inc.
crazyboblee66b415a2006-08-25 02:01:19 +00003 *
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
limpbizkit@gmail.com9a227be2010-07-03 15:51:31 +000017package com.google.inject.internal.util;
crazyboblee66b415a2006-08-25 02:01:19 +000018
19import java.lang.ref.SoftReference;
20
21/**
crazyboblee210bf432009-02-05 06:04:18 +000022 * Soft reference with a {@code finalizeReferent()} method which a background
23 * thread invokes after the garbage collector reclaims the referent. This is a
24 * simpler alternative to using a {@link java.lang.ref.ReferenceQueue}.
crazyboblee66b415a2006-08-25 02:01:19 +000025 *
crazyboblee210bf432009-02-05 06:04:18 +000026 * @author Bob Lee
crazyboblee66b415a2006-08-25 02:01:19 +000027 */
28public abstract class FinalizableSoftReference<T> extends SoftReference<T>
29 implements FinalizableReference {
30
crazyboblee210bf432009-02-05 06:04:18 +000031 /**
32 * Consructs a new finalizable soft reference.
33 *
34 * @param referent to softly reference
35 * @param queue that should finalize the referent
36 */
37 protected FinalizableSoftReference(T referent,
38 FinalizableReferenceQueue queue) {
39 super(referent, queue.queue);
limpbizkit8166e4c2009-05-03 22:40:22 +000040 queue.cleanUp();
crazyboblee66b415a2006-08-25 02:01:19 +000041 }
42}