I am really confused about what I read about the applications of volatile keyword in java.
Is the following statement correct? "a write to a volatile field happens before every subsequent read of the same field"
Ideally when should volatile keyword used?
What is the difference between:
class TestClass { private int x; synchronized int get(){return x;} synchronized void set(int x){this.x = x;} }
and
class TestClass
{ private volatile int x;
int get(){return x;}
void set(int x){this.x = x;}
}