分析BlockingQueue使用示例
我正在查看“基于典型生产者-消费者场景的使用示例”: http://download .oracle.com/javase/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html#put(E)
吗?
我认为 put 和 take 操作需要锁定某些内容 继续修改之前的资源队列,但这里没有发生这种情况。
此外,如果这是一种并发类型的队列,则缺少锁是可以理解的,因为并发队列上的原子操作不需要锁。
I was looking at the "usage example based on a typical producer-consumer scenario" at:
http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html#put(E)
Is the example correct?
I think the put and take operations need a lock on some resource before proceeding to modify the queue, but that is not happening here.
Also, had this been a Concurrent kind of a queue, the lack of locks would have been understandable since atomic operations on a concurrent queue do not need locks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 api 中编写的内容不需要添加任何内容:
I do not think there is something to add to what is written in api:
BlockingQueue 只是一个接口。该实现可以使用同步块、锁或无锁。 AFAIK 大多数方法在实现中都使用 Lock。
BlockingQueue is just an interface. This implementation could be using synchronzed blocks, Lock or be lock-free. AFAIK most methods use Lock in the implementation.