peter.petrov
peter.petrov

Reputation: 39457

LinkedBlockingQueue - unbounded - put blocking?

I have 2 simple questions here. I have a LinkedBlockingQueue which I create simply as

new LinkedBlockingQueue()

So I think this guarantees that is unbounded, is that right?
If indeed so, is it right to say that the method put can never block when called on this queue instance?

Upvotes: 1

Views: 267

Answers (1)

Platinum Azure
Platinum Azure

Reputation: 46193

The Java docs specify that a no-arg constructor invocation will result in a capacity of Integer.MAX_VALUE, which is large but not actually infinite, so the queue is bounded (but for practical purposes, it might as well not be).

The put method will block only if space needs to become available, meaning it will block if the queue already has a number of elements equal to capacity.

Upvotes: 6

Related Questions