com.raelity.org.openide.util
Class Utilities

java.lang.Object
  extended by com.raelity.org.openide.util.Utilities

public final class Utilities
extends Object

Otherwise uncategorized useful static methods.


Method Summary
static ReferenceQueue<Object> activeReferenceQueue()
          Useful queue for all parts of system that use java.lang.ref.References together with some ReferenceQueue and need to do some clean up when the reference is enqueued.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

activeReferenceQueue

public static ReferenceQueue<Object> activeReferenceQueue()
Useful queue for all parts of system that use java.lang.ref.References together with some ReferenceQueue and need to do some clean up when the reference is enqueued. Usually, in order to be notified about that, one needs to either create a dedicated thread that blocks on the queue and is Object.notify-ed, which is the right approach but consumes valuable system resources (threads) or one can periodically check the content of the queue by RequestProcessor.Task.schedule which is completely wrong, because it wakes up the system every (say) 15 seconds. In order to provide useful support for this problem, this queue has been provided.

If you have a reference that needs cleanup, make it implement Runnable and register it with the queue:

 class MyReference extends WeakReference implements Runnable {
     private final OtherInfo dataToCleanUp;
     public MyReference(Thing ref, OtherInfo data) {
         super(ref, Utilities.activeReferenceQueue());
         dataToCleanUp = data;
     }
     public void run() {
         dataToCleanUp.releaseOrWhateverYouNeed();
     }
 }
 
When the ref object is garbage collected, your run method will be invoked by calling ((Runnable) reference).run() and you can perform whatever cleanup is necessary. Be sure not to block in such cleanup for a long time as this prevents other waiting references from cleaning themselves up.

Do not call any ReferenceQueue methods. They will throw exceptions. You may only enqueue a reference.

Be sure to call this method anew for each reference. Do not attempt to cache the return value.

Since:
3.11