gpt4 book ai didi

java - ConcurrentLinkedDeque 与 LinkedBlockingDeque

转载 作者:太空狗 更新时间:2023-10-29 22:50:12 24 4
gpt4 key购买 nike

我需要一个线程安全的 LIFO 结构,我发现我可以为此使用 Deque 的线程安全实现。 Java 7 引入了 ConcurrentLinkedDeque Java 6 有 LinkedBlockingDeque .

如果我只使用 LinkedBlockingDeque 中的非阻塞方法,例如 addFirst()removeFirst() 它是否有任何与 ConcurrentLinkedDeque 的区别?

即如果忽略阻塞方面,ConcurrentLinkedDequeLinkedBlockingDeque 除了 LinkedBlockingDeque 有界之外还有其他区别吗?

最佳答案

引用伟大的Doug Lea (我的重点)

LinkedBlockingDeque vs ConcurrentLinkedDeque

The LinkedBlockingDeque class is intended to be the "standard" blocking deque class. The current implementation has relatively low overhead but relatively poor scalability. ...

... ConcurrentLinkedDeque has almost the opposite performance profile as LinkedBlockingDeque: relatively high overhead, but very good scalability. ... in concurrent applications, it is not all that common to want a Deque that is thread safe yet does not support blocking. And most of those that do are probably better off with special-case solutions.

他似乎在建议你应该使用 LinkedBlockingDeque 除非你特别需要 ConcurrentLinkedDeque 的特性。

关于java - ConcurrentLinkedDeque 与 LinkedBlockingDeque,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19179046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com