如何并行等待多个阻塞队列? [英] How to wait on multiple blocking queues in parallel?

查看:152
本文介绍了如何并行等待多个阻塞队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个单独的阻止队列。客户通常使用第二个阻塞队列中的第一个来检索要处理的元素。

I have two separated blocking queues. The clients usually use either the first of the second blocking queue to retrieve elements to be processed.

在某些情况下,客户对两个阻塞队列中的元素感兴趣,

In some case, the clients are interested in elements from the two blocking queues, whichever queue provides the data first.

客户端如何并行等待两个队列?

How can a client wait for the two queues, in parallel?

推荐答案

您可以尝试使用 投票 方法在某种循环中仅等待指定数量的

You could try using the poll method in some sort of loop to only wait a specified amount of time for one queue before polling the other one.

除此之外,我想说的是在单独的线程上为每个队列运行阻塞操作,并为您的服务器提供回调接口主要应用是另一个稍微复杂一些的选项。

Other than that, I'd say running the blocking operations for each queue on separate threads and providing a callback interface to your main application is another, slightly more complex, option.

这篇关于如何并行等待多个阻塞队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆