saker.util Documentation TaskDoc JavaDoc Packages
public class StrongWeakReference<Textends WeakReference<T>
Reference class that allows the referent to be strongly referenced alongside its weak reference.

This class works the same way as WeakReference, but when constructed, it also holds the referent by a strong reference. This prevents it from being garbage collected until makeWeak() is called.

This class is useful when dynamic caching is implemented. Making a reference weak can allow the referenced object to be garbage collected, but calling makeStrong() again, can allow the client to reuse a not yet garbage collected object instead of creating a new one.

TThe type of the referenced object.
Constructors
public
Creates a new weak reference that refers to the given object.
public
StrongWeakReference(T referent, ReferenceQueue<super T> q)
Creates a new weak reference that refers to the given object and is registered with the given queue.
Methods
public void
Clears this reference object.
public boolean
Tries to make this reference strong again, by assigning the strong reference to the referent.
public void
Makes this reference weak by clearing its strong reference.
public StrongWeakReference(T referent) throws NullPointerException
Documentation included from: WeakReference
Creates a new weak reference that refers to the given object. The new reference is not registered with any queue.
referentobject the new weak reference will refer to
public StrongWeakReference(T referent, ReferenceQueue<super T> q) throws NullPointerException
Documentation included from: WeakReference
Creates a new weak reference that refers to the given object and is registered with the given queue.
referentobject the new weak reference will refer to
qthe queue with which the reference is to be registered, or null if registration is not required
public void clear()
Overridden from: Reference
Clears this reference object. Invoking this method will not cause this object to be enqueued.

This method is invoked only by Java code; when the garbage collector clears references it does so directly, without invoking this method.

public boolean makeStrong()
Tries to make this reference strong again, by assigning the strong reference to the referent.

This method can fail and return false, if the referenced object was already garbage collected. (I.e. Reference.get() returns null.)

If this method succeeds, then the following calls to Reference.get() will return non-null.

true if the reference was successfully made strong.
public void makeWeak()
Makes this reference weak by clearing its strong reference.