1

I've read on a site that volatile keyword is used when "Essentially, volatile is used to indicate that a variable's value will be modified by different threads"

should I ALWAYS make fields volatile when they're being modified by different threads or only when I notice synchronization problems ?

  • It don't sincronizate write but read. It makes sure other threads it will always read the most-recent-written value. – Marco Acierno May 18 '14 at 16:53
  • If in doubt, make it volatile. Failing to do so when you need to results in bugs that can be very difficult to track down, while doing so when you don't need to merely makes performance a bit slower. – Warren Dew May 18 '14 at 16:56

0 Answers0