United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6327342 DelayQueue.poll(timeout, unit) can spin past given timeout
6327342 : DelayQueue.poll(timeout, unit) can spin past given timeout

Details
Type:
Bug
Submit Date:
2005-09-22
Status:
Resolved
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2005-09-30
Component:
core-libs
OS:
generic,windows_xp
Sub-Component:
java.util.concurrent
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0,6
Fixed Versions:
6

Related Reports
Backport:
Duplicate:

Sub Tasks

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);
                                     
2005-09-22
EVALUATION

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



Hardware and Software, Engineered to Work Together