简体   繁体   English

ConcurrentLinkedQueue有什么用?

[英]What is the use of ConcurrentLinkedQueue?

I am working in bluetooth in android kotlin. I found this blessed library and this class BluetoothPeripheral is using ConcurrentLinkedQueue .我在 android kotlin 从事蓝牙工作。我找到了这个有福的图书馆,而这个 class BluetoothPeripheral正在使用ConcurrentLinkedQueue I don't understand what is the use of我不明白有什么用

private val commandQueue: Queue<Runnable> = ConcurrentLinkedQueue()

I am looking this enqueue function and I cannot understand the use case in here.我正在查看这个enqueue function,我无法理解这里的用例。 what the author trying to achieved in here?作者在这里想达到什么目的?

This enqueue function calls in different place ie readCharacteristic what is the use case in this function?这个enqueue function 在不同的地方调用,即readCharacteristic这个 function 的用例是什么?

Thanks谢谢

Building on @broot's comment:基于@broot 的评论:

  1. ConcurrentLinkedQueue is part of the java.util.concurrent package which is all about collections that are thread-safe ConcurrentLinkedQueuejava.util.concurrent package 的一部分,它是线程安全的 collections
  2. A Queue is a kind of collection that is designed for efficient adding and removal. Queue是一种专为高效添加和删除而设计的集合。 Typically they offer First In First Out.通常他们提供先进先出。
  3. If you have an application that is dealing with a high throughput of tasks, producers put items in a queue and consumers take them.如果您有一个处理高吞吐量任务的应用程序,生产者将项目放入队列中,消费者接收它们。 Depending which is faster, you may have more producer threads than consumer threads, or the other way around.根据哪个更快,您可能拥有比消费者线程更多的生产者线程,反之亦然。 You achieve process isolation by using a thread-safe queue, such as ConcurrentLinkedQueue您通过使用线程安全队列实现进程隔离,例如ConcurrentLinkedQueue
  4. Some Queue implementations have bounded capacity, but a queue like ConcurrentLinkedQueue is based on a Linked List so typically have have far greater capacity, but mean that some operations, such as search might perform less well.一些 Queue 实现具有有限的容量,但像ConcurrentLinkedQueue这样的队列基于链表,因此通常具有更大的容量,但这意味着某些操作(例如搜索)可能执行得不太好。
  5. There is also a Dequeue which is a Queue that you can remove items easily from both ends.还有一个Dequeue ,它是一个Queue ,您可以轻松地从两端删除项目。

I have no idea what the Bluetooth application is about and why it needs ConcurrentLinkedQueue so I cannot comment on whether it is the "best options to use in bluetooth case"我不知道蓝牙应用程序是关于什么的,也不知道它为什么需要ConcurrentLinkedQueue ,所以我无法评论它是否是“在蓝牙情况下使用的最佳选择”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM