Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add or modify element at the head of linked blocking queue?

Or maybe will be better to use other class for synchronized access to data?

like image 825
Divers Avatar asked Mar 13 '12 09:03

Divers


People also ask

What is a linked blocking queue?

The LinkedBlockingQueue is an optionally-bounded blocking queue based on linked nodes. It means that the LinkedBlockingQueue can be bounded, if its capacity is given, else the LinkedBlockingQueue will be unbounded. The capacity can be given as a parameter to the constructor of LinkedBlockingQueue.

What happens if blocking queue is full?

Here we have a blockingQueue that has a capacity equal to 10. It means that when a producer tries to add an element to an already full queue, depending on a method that was used to add it (offer(), add() or put()), it will block until space for inserting object becomes available. Otherwise, the operations will fail.

When we should use linked blocking queue and when array blocking queue?

ArrayBlockingQueue is bounded which means the size will never change after its creation. LinkedBlockingQueue is optionally bounded which means it can optionally have an upper bound if desired. If no upper bound is specified, Integer.

Is linked blocking queue thread-safe?

BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control.


1 Answers

Use LinkedBlockingDeque if you want to manipulate both ends of a queue.

like image 193
artbristol Avatar answered Oct 19 '22 13:10

artbristol