All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.lang.ref.Reference | +----java.lang.ref.CachedReference
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
.
public CachedReference()
public CachedReference(Object referent)
public Object get()
reconstitute
method. If, in that case, the
reconstitute
method returns an object, modify this
CachedReference
to refer to the object and then return it.
public Object check()
public void set(Object referent)
public void clear()
protected Object reconstitute()
null
;
it should be overridden by any client that requires the get
method to attempt to reconstitute the referent of a cleared cached
reference.
public boolean isEnqueued() throws UnsupportedOperationException
CachedReference
class does not support reference queues, so
this method always throws an UnsupportedOperationException
.
public void register(ReferenceQueue queue) throws UnsupportedOperationException
CachedReference
class does not support reference queues, so
this method always throws an UnsupportedOperationException
.
public void unregister() throws UnsupportedOperationException
CachedReference
class does not support reference queues, so
this method always throws an UnsupportedOperationException
.
All Packages Class Hierarchy This Package Previous Next Index