ReferenceQueue has privates that should be protected

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 1.2.2
    • Component/s: core-libs
    • generic
    • generic



      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)
      ======================================================================

            Assignee:
            Mark Reinhold
            Reporter:
            Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: