How do the atomic package classes as AtomicInteger etc work

前端 未结 1 1223
悲哀的现实
悲哀的现实 2021-01-04 11:34

I have read that using atomic package classes enables us to do thread safe,lock less coding. But I am not very sure about how do the methods in the classes of atomic package

相关标签:
1条回答
  • 2021-01-04 12:27

    They use very low level instructions such as Compare and Swap, and multiple other methods from sun.misc.Unsafe class.

    Basically, a method call like compareAndSwap() will correspond to a unique processor instruction, which remove a lot of multithreading issues.

    0 讨论(0)
提交回复
热议问题