Name: skT88420 Date: 08/27/99
java.lang.ref.ReferenceQueue presumably has an enqueue() method, and it must be private or package-private.
I submit that it should be made protected, so that useful referencequeue subclasses can be made that react to an
enqueue. Assuming the signature of the method is void enqueue (Reference r), an example of a useful subclass
and related class (assuming enqueue is made protected) is:
public class ThreadReferenceQueue extends ReferenceQueue {
private ReferenceQueueThread thread;
public ThreadReferenceQueue (ReferenceQueueThread t) {
thread = t;
thread.setQueue(this);
}
protected void enqueue (Reference r) {
super.enqueue(r);
t.notify();
}
}
public abstract class ReferenceQueueThread extends Thread {
protected ThreadReferenceQueue queue;
public void setQueue(ThreadReferenceQueue q) {
if (queue == null) queue = q;
}
public synchronized void run() {
setDaemon(true);
while(true) {
try {
wait();
} catch (InterruptedException e) {
return; // Interrupt the thread to terminate it.
}
Reference r;
while ((r = queue.poll()) != null) {
enqueued(r);
}
}
}
protected abstract void enqueued (Reference r);
}
(Review ID: 94488)
======================================================================