为什么JavaAPI没有';是否为非并发环境提供有界队列实现?

为什么JavaAPI没有';是否为非并发环境提供有界队列实现?,java,queue,blockingqueue,capacity,Java,Queue,Blockingqueue,Capacity,我正在编写一个小应用程序,希望有一个有界队列。天真的做法是这样做: Queue<Integer> queue = new ArrayDeque<> (5); 然后,我制作了一个BlockingQueue,我知道它是“blocking”,并且适合我编写的作业: BlockingQueue<Integer> queue = new ArrayBlockingQueue<> (5); 我以为工作结束了,但我记得。我的应用程序使用单线程。因此,我不想有

我正在编写一个小应用程序,希望有一个有界队列。天真的做法是这样做:

Queue<Integer> queue = new ArrayDeque<> (5);
然后,我制作了一个
BlockingQueue
,我知道它是“blocking”,并且适合我编写的作业:

BlockingQueue<Integer> queue = new ArrayBlockingQueue<> (5);
我以为工作结束了,但我记得。我的应用程序使用单线程。因此,我不想有一个“性能冲击”


现在我有点困了。我想使用
BlockingQueue的
bounded构造函数,但我不想让它被同步覆盖。对于这种情况,什么可能是最好的解决方案?为什么我们没有提供有边界的“普通”队列?

JDK没有提供单线程有边界队列实现,可能是因为没有一个通用算法能够支持所有用例。例如,当队列已满时,您希望发生什么?传入元素应该被丢弃,是最后一个还是第一个

根据您的需求实现您自己的应该是微不足道的

BlockingQueue<Integer> queue = new ArrayBlockingQueue<> (5);
 * Creates an {@code ArrayBlockingQueue} with the given (fixed)
 * capacity and default access policy.