There is something i haven't yet understand about synchronized and volatile.
I understand that a thread can safe changes locally. From what i have read so far is that synchronized > volatile.
Say i have an parameter which is not long or double so basically a standard Integer ( no atomic ).
And i have a synchronized method where i do a lot work with this Integer. Will all threads get the updated version of this Integer? Or do i have to declare it volatile as well?
public class stackoverflow {
private int x = 0;
public synchronized void rechnen(){
//dosomething
}
}
basically after rechnen() is done, and i got 10000 threads, will all get the updates version of x because my method is synchronized? or do i have to declare it volatile as well?