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 provide thread safety in absence of use of locks or any synchronize keyword.Any help shall be appreciated.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With