小编emu*_*emu的帖子

同时迭代BlockingQueue

在使用a的应用程序中BlockingQueue,我面临的新要求只能通过迭代队列中存在的元素来实现(以提供有关元素当前状态的信息).

根据API JavadocBlockingQueue实现的唯一排队方法,只需要是线程安全的.Other API methods(例如,从中继承的那些Collection interface)可能不会同时使用,但我不确定这是否也适用于纯读取访问...

我可以安全地使用iterator() WITHOUT altering the producer/consumer threads哪些通常可以随时与队列交互?我不需要a 100% consistent iteration(在迭代队列时我是否看到添加/删除元素并不重要),但我不想最终讨厌ConcurrentModificationExceptions.

请注意,该应用程序当前正在使用a LinkedBlockingQueue,但我可以自由选择任何其他(unbounded) BlockingQueue implementation(包括free open-source third-party implementations).此外,我不想依赖将来可能会破坏的东西,所以我想要一个根据的解决方案,API并且不仅仅是恰好与之合作current JRE.

java concurrency multithreading blockingqueue

4
推荐指数
2
解决办法
2794
查看次数

标签 统计

blockingqueue ×1

concurrency ×1

java ×1

multithreading ×1