Exo*_*mus 3 java multithreading
提供块调查,反之亦然?意思是,生产者可以提供并同时消费者试图进行民意调查吗?或者如果生产者提供,队列会阻塞直到他完成?
对象A.
while (true){
inputQueue.offer(newPartList);
}
Run Code Online (Sandbox Code Playgroud)
对象B.
while (true){
inputQueue.poll(newPartList);
}
Run Code Online (Sandbox Code Playgroud)
不,不是的.请改用LinkedBlockingDeque.请记住使用BlockingDequeue或BlockingQueue接口中的方法来获取值.因为这些方法是作为阻塞实现的.
更新
这两种方法都offer没有poll阻止.仅在链接接口中put*,take*方法实现为阻止.put只要队列已满,就take阻塞,如果队列为空则阻塞.
现在我看到你在问别的什么.在LinkedBlockingDeque中 调用offer块poll,因为此实现具有Lock用于同步访问的内容.在ConcurrentLinkedQueue的 JavaDoc中明确声明:
This implementation employs an efficient "wait-free" algorithm based on one described in简单,快速,实用的非阻塞和阻塞并发队列算法by Maged M. Michael and Michael L. Scott.
这表明这些操作不会相互阻碍.如果您有兴趣,我强烈建议阅读该论文以获得更多见解.
| 归档时间: |
|
| 查看次数: |
5573 次 |
| 最近记录: |