Understanding of the volatile (3)

The difference between volatile and synchronize

1.volatile not guarantee atomicity, visibility of the parameters can only be modified, synchronize can guarantee thread safety

2.volatile only modifies parameters can not be modified method, synchronize only modification methods

3. When multiple threads on the same parameters can be modified using the volatile since the parameters of the thread is visible, use synchronize efficiency will be lower

Guess you like

Origin www.cnblogs.com/siyuan7657/p/12594694.html