This Java tutorial is to learn about TransferQueue which is concurrent collection.
TransferQueue is an interface and a type of BlockingQueue. TransferQueue extends from BlockingQueue interface to add behavior to it. In a TransferQueue producers may wait for consumers to receive elements. TransferQueue was added in Java SE 7.
This is marginally similar to the SynchronousQueue. In a SynchronousQueue the producer will always wait for a consumer. Once there is a consumer ready, the producer will push the item into the SynchrounousQueue and the item will be immediately consumed. So at any instance the queue length will always be zero.
In the case of TransferQueue, the producer with wait for the consumer to receive elements. The limit can be specified. Here the item can stay in the queue. This queue is useful in messaging applications. TransferQueue can be used as a pipeline to pass messages between channels.
Difference between BlockingQueue and TransferQueue
- In BlockingQueue, we can put element into the queue and block if the queue reaches its limit.
- In TransferQueue, we can additionally block until a thread consumes the element using the
- TransferQueue extends the BlockingQueue.
LinkedTransferQueue is an unbounded TranserQueue implementation available with the SDK.
This Java tutorial was added on 09/11/2014.