src/share/classes/java/lang/ref/ReferenceQueue.java

Print this page
rev 905 : imported patch ref

@@ -49,11 +49,11 @@
     static ReferenceQueue NULL = new Null();
     static ReferenceQueue ENQUEUED = new Null();
 
     static private class Lock { };
     private Lock lock = new Lock();
-    private Reference<? extends T> head = null;
+    private volatile Reference<? extends T> head = null;
     private long queueLength = 0;
 
     boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */
         synchronized (r) {
             if (r.queue == ENQUEUED) return false;

@@ -93,10 +93,12 @@
      *
      * @return  A reference object, if one was immediately available,
      *          otherwise <code>null</code>
      */
     public Reference<? extends T> poll() {
+        if (head == null)
+            return null;
         synchronized (lock) {
             return reallyPoll();
         }
     }