java - Using LongAdder to calculate a max value for a statistical counter? -


we collect statistics using atomiclongs. users seeing contention on these , have suggested using longadder instead. see no way calculate maximum value doing atomic:

atomiclong _current, _total, _max; ...  void add(long delta) {   long current = _current.addandget(delta);   if (delta>0)   {     _total.addandget(delta);     long max = _max.get();     while (current > max)     {       if (_max.compareandset(max, current))         break;       max = _max.get();     }  } 

so think can replace _total enough longadder, because _current.addandget(delta) not work longadder, nor can cas operation `_max' value.

are there algorithms collecting such statistics based on longadder or similar scalable lock free constructs?

actually, whiles i'm asking, our stats typically update 6 10 atomiclongs. if seeing contention anyway, possibly better grab lock , update 6 10 normal longs?

you don't want longadder, longaccumulator here: want new longaccumulator(math::max, long.min_value), right thing here. longadder special case of longaccumulator.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -