2
IBM(请参阅源代码)写了关于Java的1.5 java.util.concurrent类的好处,它提供了非阻塞队列。非阻塞队列
请解释下面的NonBlockingCounter的弱点/缺点。
public class NonblockingCounter {
private AtomicInteger value;
public int getValue() {
return value.get();
}
public int increment() {
int v;
do {
v = value.get();
}
while (!value.compareAndSet(v, v + 1)); // params - (actual, expected)
return v + 1;
}
}
来源 - http://www.ibm.com/developerworks/java/library/j-jtp04186/index.html