atomic increment of long variable?

前端 未结 4 1101
南旧
南旧 2020-12-11 16:01

if a long variable is declared as :-

private volatile long counter = 0;

now if i increment it using pre-increment operator, then would the o

4条回答
  •  庸人自扰
    2020-12-11 16:47

    The pre-increment operator is not atomic. Also, incrementing a volatile long is likely to be less efficient than using AtomicLong on almost all platforms, because the latter is supported by hardware.

提交回复
热议问题