This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Precision of BlockingQueue.poll timeout?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic