I have a use case for high concurrent writes to an AtomicLong variable. I just need to set current epoc time in this variable. What would be the fastest way to do so?
Is LongAccumulator.accumulate a better alternative to AtomicLong.set, are there any stats out there which tell after how many concurrent requests/second which is better if I just want to set variable to some value without any addition or calculation?
Simply, share
longbetweenthreadssafetly just neetvolatilekeyword like:So, if you just use it like this, it will enought.
But for your question, if you examine source codes
AtomicLong source:
LongAccumulator source:
So,
AtomicLongis better for performance because of less code :)