org.openide.util
Class TimedSoftReference<T>

java.lang.Object
  extended by java.lang.ref.Reference<T>
      extended by java.lang.ref.SoftReference<T>
          extended by org.openide.util.TimedSoftReference<T>
All Implemented Interfaces:
java.lang.Runnable

final class TimedSoftReference<T>
extends java.lang.ref.SoftReference<T>
implements java.lang.Runnable

A soft reference which is held strongly for a while after last access. Lifecycle:

  1. Created. Referent held strongly. A task is scheduled into the request processor for some time in the future (currently 30 seconds).
  2. Expired. After the timeout, the reference switches to a normal soft reference.
  3. Touched. If the value is accessed before it is garbage collected, whether the reference is expired or not, the reference is "touched". This means that the referent is again held strongly and the timeout is started from scratch.
  4. Dead. If after expiry there is no access before the next full GC cycle, the GC algorithm may reclaim the reference. In this case the reference of course dies. As a bonus, it will try to remove itself as the value from a map of your choice, to make it convenient to use these references as values in a caching map without leaking memory for the key.

Author:
Jesse Glick

Constructor Summary
TimedSoftReference(T o, java.util.Map m, java.lang.Object k)
          Create a soft reference with timeout.
 
Method Summary
 T get()
           
 void run()
           
 
Methods inherited from class java.lang.ref.Reference
clear, enqueue, isEnqueued
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimedSoftReference

public TimedSoftReference(T o,
                          java.util.Map m,
                          java.lang.Object k)
Create a soft reference with timeout. The supplied map serves double duty as a synchronization lock for the reference's state changes.

Parameters:
o - the referent
m - a map in which this reference may serve as a value
k - the key whose value in m may be this reference
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

get

public T get()
Overrides:
get in class java.lang.ref.SoftReference<T>