why using volatile with synchronized block?
I saw some examples in java where they do synchronization on a block of code to change some variable while that variable was declared volatile originally .. I saw that in an example of singleton class where they declared the unique instance as volatile and they sychronized the block that initializes that instance ... My question is why we declare it volatile while we synch on it, why we need to do both?? isn't one of them is sufficient for the other ?? public class someClass { volatile static uniqueInstance = null; public static someClass getInstance() { if(uniqueInstance == null) {