All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class java.lang.ref.CachedReference

java.lang.Object
    |
    +----java.lang.ref.Reference
            |
            +----java.lang.ref.CachedReference

public class CachedReference
extends Reference
The CachedReference class implements cached weak references. When memory gets tight, an instance of this class may be cleared automatically if its referent is reachable only via CachedReference instances and, perhaps, via other weak or phantom references. The CachedReference class makes a best effort to clear all CachedReference instances before the virtual machine throws an OutOfMemoryError.

If the get method of a cleared CachedReference is invoked, it will in turn invoke the reconstitute method in an attempt to reconstruct the original referent. Thus while the CachedReference class is useful as it stands, it can profitably be subclassed by overriding the default reconstitute method and adding any fields required to recreate the original referent.

Unlike most subclasses of the Reference class, the CachedReference class does not support notification via reference queues. The isEnqueued, register, and unregister methods therefore always throw UnsupportedOperationException.

Since:
JDK1.2
See Also:
Reference, Runtime.MemoryAdvice

Constructor Index

 o CachedReference()
Construct a new, initially clear cached reference.
 o CachedReference(Object)
Construct a new cached reference that refers to the given object.

Method Index

 o check()
Return the referent of this cached reference, if any, without attempting to reconstitute it if the reference has been cleared.
 o clear()
Clear this cached reference.
 o get()
Return the object to which this cached reference refers.
 o isEnqueued()
Tell whether or not this reference has been enqueued.
 o reconstitute()
Reconstitute the object to which this reference once referred.
 o register(ReferenceQueue)
Register this reference object with the given queue.
 o set(Object)
Modify this cached reference to refer to the given object.
 o unregister()
Cancel the registration of this reference object.

Constructors

 o CachedReference
public CachedReference()
Construct a new, initially clear cached reference.

 o CachedReference
public CachedReference(Object referent)
Construct a new cached reference that refers to the given object.

Methods

 o get
public Object get()
Return the object to which this cached reference refers. If the reference has been cleared, then attempt to recreate it by invoking the reconstitute method. If, in that case, the reconstitute method returns an object, modify this CachedReference to refer to the object and then return it.

Overrides:
get in class Reference
 o check
public Object check()
Return the referent of this cached reference, if any, without attempting to reconstitute it if the reference has been cleared.

 o set
public void set(Object referent)
Modify this cached reference to refer to the given object.

Overrides:
set in class Reference
 o clear
public void clear()
Clear this cached reference.

Overrides:
clear in class Reference
 o reconstitute
protected Object reconstitute()
Reconstitute the object to which this reference once referred. The default implementation of this method simply returns null; it should be overridden by any client that requires the get method to attempt to reconstitute the referent of a cleared cached reference.

 o isEnqueued
public boolean isEnqueued() throws UnsupportedOperationException
Tell whether or not this reference has been enqueued. The CachedReference class does not support reference queues, so this method always throws an UnsupportedOperationException.

Throws: UnsupportedOperationException
Always thrown, because reference queues are not supported
Overrides:
isEnqueued in class Reference
 o register
public void register(ReferenceQueue queue) throws UnsupportedOperationException
Register this reference object with the given queue. The CachedReference class does not support reference queues, so this method always throws an UnsupportedOperationException.

Throws: UnsupportedOperationException
Always thrown, because reference queues are not supported
Overrides:
register in class Reference
 o unregister
public void unregister() throws UnsupportedOperationException
Cancel the registration of this reference object. The CachedReference class does not support reference queues, so this method always throws an UnsupportedOperationException.

Throws: UnsupportedOperationException
Always thrown, because reference queues are not supported
Overrides:
unregister in class Reference

All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Submit a bug or feature