I have an application which are multi threading. I notice some existing code use volatile when the variable is shared by several threads. Why not just use synchronized in the method when variable is used, what’s the benefits to define variable as volatile?
Share
Declaring a volatile Java variable means:
In other words, the main differences between synchronized and volatile are:
more information is: http://javamex.com/tutorials/synchronization_volatile.shtml