• Post Reply Bookmark Topic Watch Topic
  • New Topic

Precision of BlockingQueue.poll timeout?  RSS feed

Mario Zagar
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

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


Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!