ConcurrentLinkedDeque vs LinkedBlockingDeque

后端 未结 4 1636
故里飘歌
故里飘歌 2021-02-07 05:53

I need to have a thread-safe LIFO structure and found that I can use thread-safe implementations of Deque for this. Java 7 has introduced ConcurrentLinkedDeque and

4条回答
  •  面向向阳花
    2021-02-07 06:34

    To quote the great Doug Lea (my emphasis)

    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.

    He seems to be suggesting that you should use LinkedBlockingDeque unless you specifically need the features of ConcurrentLinkedDeque.

提交回复
热议问题