aspose file tools*
The moose likes Java in General and the fly likes Precision of BlockingQueue.poll timeout? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Precision of BlockingQueue.poll timeout?" Watch "Precision of BlockingQueue.poll timeout?" New topic
Author

Precision of BlockingQueue.poll timeout?

Mario Zagar
Greenhorn

Joined: Feb 18, 2010
Posts: 1
Hello all,

I am experiencing unusually long waits before timeout when using BlockingQueue<T>.poll(long timeout, TimeUnit unit).

I would expect poll() to timeout within operating system timer precision error (e.g. 15ms on Windows).

According to my tests poll() waits alot longer.
For example, if timeout is set to 2000ms, poll() timeout occurrs after ~3200ms and not after (as I would expect) ~2015ms.

I do not understand why the precision of BlockingQueue.poll() timeout is so poor.

If I cannot rely on poll() to wait "up to" (as stated in javadoc) specified timeout, I do not see the practical use for this method.
(or should "up to" be understood as "never less than but can be extremly over specified timeout")

Could anyone please shed some light on this matter and maybe point me in the right direction as to what am I doing wrong ?
Is my understanding of what poll() should be used for and when wrong ?


Here is my test code which measures how long did poll() wait before timing out & the resulting output.
(Windows XP SP3, jre 1.6.0.18)



Resulting output:

i=0, poll timeout after: 2422
i=1, poll timeout after: 3156
i=2, poll timeout after: 3219
i=3, poll timeout after: 3281
i=4, poll timeout after: 3203
i=5, poll timeout after: 2829
i=6, poll timeout after: 2843
i=7, poll timeout after: 3282
i=8, poll timeout after: 3125
i=9, poll timeout after: 3250


Regards,

Mario
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Precision of BlockingQueue.poll timeout?