St.Antario
St.Antario

Reputation: 27385

Why doesn't a method which would block untill the queue become non-empty?

In the blocking queue documentation said that the method which examine and block the queue until it becomes non-empty is not applicable. But to me it's not clear why. Couldn't you explain that?

Upvotes: 1

Views: 52

Answers (1)

Gaz
Gaz

Reputation: 328

Maybe you are misunderstanding that part of the documentation (the table which groups the different methods into four categories) ?

The javadoc is simply saying that the BlockingQueue class has no need for a method which may block (or time out) when it examines the content of the queue, unlike actions such as inserting or removing items into/from the queue, where you may need the options of waiting or timing out if the queue is 'unavailable' at that precise moment.

I don't know exactly why this is, but I can make an educated guess: if you want to look inside a queue, you may get an exception, or you may get a value returned, but then the code will just move on from there -- you can't really block or time out.

Upvotes: 1

Related Questions