11

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.

4

3 回答 3

6

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.

于 2013-03-17T12:42:40.883 回答
1

您可以使用“BlockingQueue”,下面的链接可以帮助您更好地了解它

BlockingQueue , 队列实现

于 2013-03-17T12:45:33.533 回答
-2

同步队列怎么样?参考:http ://docs.oracle.com/javase/7/docs/api/java/util/concurrent/SynchronousQueue.html

于 2013-03-17T12:43:46.377 回答