Java中是否有同步队列? [英] Is there a synchronized queue in Java?

查看:32
本文介绍了Java中是否有同步队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中是否有同步的 Queue 类?我正在寻找类似 Vector(它是同步的)与 ArrayList(它不是)之类的东西,而不是实现 List 接口,我正在寻找它来实现 Queue.

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.

请注意,没有 Collections.synchronizedQueue 方法可以包装未同步的队列并使其同步.

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

推荐答案

查看 ArrayBlockingQueue 和另一个 BlockingQueue 实现.

Look at ArrayBlockingQueue and another BlockingQueue implementations.

来自文档:

额外支持在检索元素时等待队列变为非空以及在存储元素时等待队列中有可用空间的操作的队列.

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.

这篇关于Java中是否有同步队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆