JDK-6327342 : DelayQueue.poll(timeout, unit) can spin past given timeout
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2005-09-22
  • Updated: 2010-04-02
  • Resolved: 2005-09-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u7Fixed 6 b55Fixed
Related Reports
Duplicate :  
Description
Doug Lea writes:

When unexpired elements remain, DelayQueue.poll(timeout, unit)
may busy-wait past the given timeout until one expires.

A test case is in src/test/tck/DelayQueueTest. This
hangs (for about 293 years) rather than returning in a few
milliseconds. (A stand-alone test isn't worth writing).

     public void testTimedPollDelayed() {
         DelayQueue q = new DelayQueue();
         q.add(new NanoDelay(Long.MAX_VALUE));
         try {
             assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
         } catch (Exception ex) {
             unexpectedException();
         }
     }

Comments
SUGGESTED FIX Index: DelayQueue.java =================================================================== RCS file: /export/home/jsr166/jsr166/jsr166/src/main/java/util/concurrent/DelayQueue.java,v retrieving revision 1.39 diff -c -r1.39 DelayQueue.java *** DelayQueue.java 20 Aug 2005 07:41:47 -0000 1.39 --- DelayQueue.java 22 Sep 2005 00:14:14 -0000 *************** *** 203,208 **** --- 203,210 ---- } else { long delay = first.getDelay(TimeUnit.NANOSECONDS); if (delay > 0) { + if (nanos <= 0) + return null; if (delay > nanos) delay = nanos; long timeLeft = available.awaitNanos(delay);
22-09-2005

EVALUATION Doug Lea is providing a fix.
22-09-2005