Java volatile reference vs. AtomicReference

后端 未结 6 1079
慢半拍i
慢半拍i 2020-11-28 02:06

Is there any difference between a volatile Object reference and AtomicReference in case I would just use get() and set()-

6条回答
  •  眼角桃花
    2020-11-28 02:48

    AtomicReference provides additional functionality which a plain volatile variable does not provide. As you have read the API Javadoc you will know this, but it also provides a lock which can be useful for some operations.

    However, unless you need this additional functionality I suggest you use a plain volatile field.

提交回复
热议问题