Quick clarification please

I know BlockingQueues are threadsafe.

Does that mean that I can pass a single reference to a blocking queue to all producers who can drop Events in willy-nilly to be consumed by a single consumer, and nothing gets disrupted?

Otherwise having to produce up to 20 BlockingQueues that may or may not have regular updates and reading them with any efficiency seems an insurmountable task.

有帮助吗?

解决方案

Does that mean that I can pass a single reference to a blocking queue to all producers who can drop Events in willy-nilly to be consumed by a single consumer, and nothing gets disrupted?

In a word, yes. This is safe. To quote the documentation:

BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control.

其他提示

If it's threadsafe that means that you only need one instance of that queue which can be accessed by all threads. The concurrent data structure manages those accesses. This also means that no synchronization from your side is needed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top