我只是想知道为什么他们做了一个LinkedBlockingDeque,而相同的非并发对应物是一个支持在可调整大小的数组上的ArrayDeque。
LinkedBlockingQueue使用一组类似于LinkedList的节点(即使没有实现List)。
我知道使用ArrayBlockingQueue的可能性,但如果有人想使用ArrayBlockingDeque怎么办?为何没有这样的选择呢?
提前谢谢。
发布于 2013-07-18 14:13:12
这可能不是一个恰当的问题w.r.t stackoverflow。但是我想说一些关于这些实现的事情。
->首先我们需要回答为什么我们为某个接口提供了不同的实现。假设我们有一个接口A,有两个实现,假设B和C。现在假设这些实现通过它们的实现提供了相同的功能。但是B的性能比C好。那么除了两个原因之外,我们应该删除这个实现。
1. Backward Compatibility - marking as deprecated.
2. There is a specific scenario where we cannot use B implementation.例如:
HashMap和LinkedHashMap ->如果我需要有序密钥,我将使用LinkedHashMap,否则我将使用HashMap (为了提高一点性能)。
ArrayBlockingQueue vs LinkedBlockingQueue如果我需要有界队列,我将使用ArrayBlockingQueue,否则我将使用LinkedBlockingQueue。
现在你的问题是,为什么没有ArrayBlockingDeque,而LinkedBlockingDeque存在。
首先,让我们看看ArrayDeque为什么会存在。
来自ArrayDeque的Java文档。
还要注意的是,ArrayDeque没有容量限制。在LinkedList implementation.中使用时,它还有两个指向头部和尾部的指针
因此,如果有ArrayBlockingDeque的话。
1. There would have been no Capacity Restriction, which we normally
get from ArrayBlockingQueue.
2. There would have guards to access to tail and head pointers
same as in LinkedBlockingDeque and therefore no significant performance
gain over LinkedBlockingDeque.因此,结论是没有ArrayBlockingDeque实现,因为这个实现没有任何额外的东西可以通过LinkedBlockingDeque提供。如果你能证明有一些东西,那么是的,实现需要在那里:)
https://stackoverflow.com/questions/17674931
复制相似问题