Is there a synchronized queue in Java?

Shelef picture Shelef · Mar 17, 2013 · Viewed 22.7k times · Source

Is there a synchronized Queue class in Java? I'm looking for something like Vector (which is synchronized) vs ArrayList (which is not), but instead of implementing the List interface, I'm looking for it to implement Queue.

Note that there is no Collections.synchronizedQueue method to wrap an unsynchronized queue and make it synchronized.

Answer

bsiamionau picture bsiamionau · Mar 17, 2013

Look at ArrayBlockingQueue and another BlockingQueue implementations.

From documentation:

A Queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element.