Java高并发17-LongAccumulator类详解
2021-06-10 15:04
//LongAccumulator的accumulate方法//LongAdder的add方法
public void add(long x){
Cell[] as;
long b;
long v;
int m;
Cell a;
if(as = cells) != null || !casBase(b = base,b+x)) {
boolean uncontended = true;
if(as == null || (m = as.length -1)0 || (a = as[getProbe() & m]) == null || !(uncontended = a.cas(v = a.value,v + x))){
longAccumulator(x,null,uncontended);
}
}
}
public void accumulate(long x){
Cell[] as;
long b;
long v;
int m;
Cell a;
if(as = cells) != null || r = function.applyAsLong(b = base,x))!= b && !casBase(b,r) {
boolean uncontended = true;
if(as == null || (m = as.length -1)0 || (a = as[getProbe() & m]) == null || !(uncontended = (r = function.applyAsLong(v = a.value,x)) == v|| a.cas(v,r))){
longAccumulator(x,null,uncontended);
}
}
文章标题:Java高并发17-LongAccumulator类详解
文章链接:http://soscw.com/index.php/essay/93198.html