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

Print this page

        

*** 23,32 **** --- 23,34 ---- * questions. */ package java.lang.ref; + import static java.util.concurrent.TimeUnit.*; + /** * Reference queues, to which registered reference objects are appended by the * garbage collector after the appropriate reachability changes are detected. * * @author Mark Reinhold
*** 136,150 **** throw new IllegalArgumentException("Negative timeout value"); } synchronized (lock) { Reference<? extends T> r = reallyPoll(); if (r != null) return r; for (;;) { lock.wait(timeout); r = reallyPoll(); if (r != null) return r; ! if (timeout != 0) return null; } } } /** --- 138,158 ---- throw new IllegalArgumentException("Negative timeout value"); } synchronized (lock) { Reference<? extends T> r = reallyPoll(); if (r != null) return r; + long start = (timeout == 0) ? 0 : System.nanoTime(); for (;;) { lock.wait(timeout); r = reallyPoll(); if (r != null) return r; ! if (timeout != 0) { ! long end = System.nanoTime(); ! timeout -= NANOSECONDS.toMillis(end - start); ! if (timeout <= 0) return null; ! start = end; ! } } } } /**