API这么一段换,英语不咋地,有点看不懂,求翻译、求指教
However之后看不懂鸟BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control. However, the bulk Collection operations addAll, containsAll, retainAll and removeAll are not necessarily performed atomically unless specified otherwise in an implementation. So it is possible, for example, for addAll(c) to fail (throwing an exception) after adding only some of the elements in c.
However之后看不懂鸟BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control. However, the bulk Collection operations addAll, containsAll, retainAll and removeAll are not necessarily performed atomically unless specified otherwise in an implementation. So it is possible, for example, for addAll(c) to fail (throwing an exception) after adding only some of the elements in c.
解决方案 »
- 在定义方法中抛出多个异常,想在main中怎么一一catch处理?
- 如何在 JPopupMenu 中添加一个滚动条?
- Swing编程的问题!..>>急急急..在线等..>>>
- 请问我如果用jdk1.5,tomcat5.5开发,那么hibernate,spring,struts有支持jdk1.5的版了吗
- 为什么这段连接数据库代码,未能在界面上获得查询结果?毕业设计一部分,谢谢指导
- 高手来看看!关于计算代码中注释行算法的问题。
- 关于java图形处理的问题
- 大家快来加入这个JAVA群~~一起学习一起进步~!(1416551)
- jbuilder的问题java.lang.NoClassDefFoundError: ...是什么例外?
- 关于如何取得数据库某一张表格的字段数以及................
- 一个窗体浮在另一个窗体之上
- 为什么要使用内部类
不会吧?BlockingQueue 接口的实现必须是线程安全的!
他的父类是AbstractQueue,里面有addAll这个方法,大侠们帮忙鉴定一下,我感觉根本不是同步的:
public boolean addAll(Collection<? extends E> c) {
if (c == null)
throw new NullPointerException();
if (c == this)
throw new IllegalArgumentException();
boolean modified = false;
for (E e : c)
if (add(e))
modified = true;
return modified;
}
里面又调用了add:
public boolean add(E e) {
if (offer(e))
return true;
else
throw new IllegalStateException("Queue full");
}
又调用了offer这offer没找着实现悲剧鸟
BlockingQueue实现是线程安全的。所有的队列方法的行为都是使用内部锁或其它并发控制的行式实现原子性,然而,大集合的操作addAll, containsAll, retainAll and removeAll没有必要实现原子性除非在实现中指定了。所以可能发生这样的事儿,例如,addAll(c)失败(抛出一个异常)之后可能添加进去的只是c中一部分元素。
意思大概就是说:
BlockingQueue本身的方法是线程安全的
但是addAll, containsAll, retainAll and removeAll不是线程安全的。