gpt4 book ai didi

java - SynchronousQueue 与 TransferQueue 之间的区别

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:20:35 27 4
gpt4 key购买 nike

这两种实现有什么区别?在哪些情况下应优先使用?

最佳答案

this post by Alex Miller 中所述

TransferQueue is more generic and useful than SynchronousQueue however as it allows you to flexibly decide whether to use normal BlockingQueue semantics or a guaranteed hand-off. In the case where items are already in the queue, calling transfer will guarantee that all existing queue items will be processed before the transferred item.

SynchronousQueue implementation uses dual queues (for waiting producers and waiting consumers) and protects both queues with a single lock. The LinkedTransferQueue implementation uses CAS operations to form a nonblocking implementation and that is at the heart of avoiding serialization bottlenecks.

关于java - SynchronousQueue 与 TransferQueue 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27218688/

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