在使用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.