似于Java的LinkedBlockingQueue的阻塞FIF

似于Java的LinkedBlockingQueue的阻塞FIF

本文介绍了C#:需要类似于Java的LinkedBlockingQueue的阻塞FIFO队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要与Java的LinkedBlockingQueue类似的东西.

need something similiar with java's LinkedBlockingQueue.

感兴趣的方法:messageQueue.poll(120000, TimeUnit.MILLISECONDS);意思是..尝试获取项目..如果在X单位时间内您仍然没有项目..返回null

method of interest: messageQueue.poll(120000, TimeUnit.MILLISECONDS);meaning ..try to get item..and if in X unit of time you still have no item..return null

该+我必须为 FIFO

经过一番谷歌搜索(但尚未经过测试):我发现ConcurrentQueue(具有FIFO行为),BlockingCollection(FiFO或没有FIFO?)

after some googling (but havent yet tested): i found ConcurrentQueue (has FIFO behaviour), BlockingCollection (FiFO OR no FIFO??)

推荐答案

BlockingCollection可以与任意数量的不同类型的集合一起使用.如果您不手动传递特定类型的并发集合,它将使用ConcurrentQueue,这意味着它将完全按照您的要求进行操作.您可以使用并发堆栈类型,也可以使用并发优先级队列,这就是为什么它使用通用名称(例如Blocking Collection而不是BlockingConcurrentQueue)的原因.

BlockingCollection can be used with any number of different types of collections. If you don't manually pass in a specific type of concurrent collection it will uses a ConcurrentQueue, meaning it will do exactly what you want. You can uses a concurrent stack type, or a concurrent priority queue if you want, which is why it uses a general name such as Blocking Collection, and not BlockingConcurrentQueue.

如果您不想相信我的话,那么所有这些都在BlockingCollection的MSDN页面上列出.

All of this is listed on the MSDN page for BlockingCollection if you don't want to take my word for it.

这篇关于C#:需要类似于Java的LinkedBlockingQueue的阻塞FIFO队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:42